from datetime import datetime as Datetime

import pytest

from delta_barth.api import requests as requests_


@pytest.mark.api_con_required
def test_get_sales_prognosis_data(session):
    resp, state = session.login()
    # test without company ID
    assert state.code == 0
    date = Datetime(2022, 6, 1)
    resp, state = requests_.get_sales_prognosis_data(session, None, date)
    assert state.code == 0
    assert len(resp.daten) > 0
    date = Datetime(2030, 1, 1)
    resp, state = requests_.get_sales_prognosis_data(session, None, date)
    assert state.code == 0
    assert len(resp.daten) == 0
    # test with company ID
    assert state.code == 0
    date = Datetime(2022, 6, 1)
    company_id = 1024
    resp, state = requests_.get_sales_prognosis_data(session, company_id, date)
    assert state.code == 0
    assert len(resp.daten) > 0
    date = Datetime(2030, 1, 1)
    resp, state = requests_.get_sales_prognosis_data(session, company_id, date)
    assert state.code == 0
    assert len(resp.daten) == 0
    # test with non-existent company ID
    assert state.code == 0
    date = Datetime(2022, 6, 1)
    company_id = 1000024
    resp, state = requests_.get_sales_prognosis_data(session, company_id, date)
    # TODO check if this behaviour is still considered "successful"
    assert state.code == 0
    assert len(resp.daten) == 0
    # test without date
    company_id = 1024
    resp, state = requests_.get_sales_prognosis_data(session, company_id, None)
    assert state.code == 0
    assert len(resp.daten) > 0
    # test without filters
    resp, state = requests_.get_sales_prognosis_data(session, None, None)
    assert state.code == 0
    assert len(resp.daten) > 0
    # close connection
    resp, state = session.logout()
    assert state.code == 0
