import enum
from pathlib import Path
from typing import Final

from delta_barth.types import DualDict, HttpContentHeaders

# ** config

# ** lib path
lib_path = Path(__file__).parent
assert lib_path is not None, "lib path not resolved"
LIB_PATH: Final[Path] = lib_path
dummy_data_pth = LIB_PATH / "_dummy_data"
assert dummy_data_pth.exists(), f"dummy data path not found: {dummy_data_pth}"
DUMMY_DATA_PATH: Final[Path] = dummy_data_pth

# ** logging
ENABLE_LOGGING: Final[bool] = False
LOGGING_TO_FILE: Final[bool] = True
LOGGING_TO_STDERR: Final[bool] = True
LOG_FILENAME: Final[str] = "dopt-delbar.log"

# ** databases
DB_ECHO: Final[bool] = True

# ** error handling
DEFAULT_INTERNAL_ERR_CODE: Final[int] = 100
DEFAULT_API_ERR_CODE: Final[int] = 400


HTTP_BASE_CONTENT_HEADERS: Final[HttpContentHeaders] = {
    "Content-type": "application/json",
    "Accept": "application/json",
}


class KnownDelBarApiErrorCodes(enum.Enum):
    COMMON = frozenset((400, 401, 409, 500))


# ** API response parsing
# ** column mapping [API-Response --> Target-Features]
COL_MAP_SALES_PROGNOSIS: Final[DualDict[str, str]] = DualDict(
    artikelId="artikel_refid",
    firmaId="firma_refid",
    betrag="betrag",
    menge="menge",
    buchungsDatum="buchungs_datum",
)

FEATURES_SALES_PROGNOSIS: Final[frozenset[str]] = frozenset(
    (
        "firma_refid",
        "betrag",
        "buchungs_datum",
    )
)


# ** Pipelines
# ** Forecast
SALES_MIN_NUM_DATAPOINTS: Final[int] = 36
SALES_BASE_NUM_DATAPOINTS_MONTHS: Final[int] = 36
