"""Predefined expense types for automatic accounting entry generation."""

from decimal import Decimal
from dataclasses import dataclass
from typing import Dict, Optional


@dataclass
class ExpenseType:
    """Expense type definition with accounting configuration."""
    code: str
    name: str
    account_code: str
    account_name: str
    has_vat: bool
    vat_percent: Decimal = Decimal("19")
    vat_account: str = "4426"


# Predefined expense types
EXPENSE_TYPES: Dict[str, ExpenseType] = {
    "FUEL": ExpenseType(
        code="FUEL",
        name="Combustibil",
        account_code="6022",
        account_name="Cheltuieli cu combustibilii",
        has_vat=True,
    ),
    "MATERIALS": ExpenseType(
        code="MATERIALS",
        name="Materiale consumabile",
        account_code="6028",
        account_name="Alte cheltuieli cu materiale consumabile",
        has_vat=True,
    ),
    "OFFICE": ExpenseType(
        code="OFFICE",
        name="Rechizite birou",
        account_code="6024",
        account_name="Cheltuieli privind materialele pentru ambalat",
        has_vat=True,
    ),
    "PHONE": ExpenseType(
        code="PHONE",
        name="Telefonie / Internet",
        account_code="626",
        account_name="Cheltuieli postale si taxe de telecomunicatii",
        has_vat=True,
    ),
    "PARKING": ExpenseType(
        code="PARKING",
        name="Parcare",
        account_code="6022",
        account_name="Cheltuieli cu combustibilii",
        has_vat=True,
    ),
    "FOOD": ExpenseType(
        code="FOOD",
        name="Alimentatie",
        account_code="6028",
        account_name="Alte cheltuieli cu materiale consumabile",
        has_vat=False,  # No deductible VAT for food
    ),
    "TRANSPORT": ExpenseType(
        code="TRANSPORT",
        name="Transport",
        account_code="624",
        account_name="Cheltuieli cu transportul de bunuri si personal",
        has_vat=True,
    ),
    "OTHER": ExpenseType(
        code="OTHER",
        name="Altele",
        account_code="628",
        account_name="Alte cheltuieli cu serviciile executate de terti",
        has_vat=True,
    ),
}


def get_expense_type(code: str) -> Optional[ExpenseType]:
    """Get expense type by code."""
    return EXPENSE_TYPES.get(code)


def get_all_expense_types() -> Dict[str, ExpenseType]:
    """Get all expense types."""
    return EXPENSE_TYPES.copy()


# Default cash register accounts
CASH_REGISTER_ACCOUNTS = {
    "CASA": {
        "code": "5311",
        "name": "Casa in lei",
    },
    "BANCA": {
        "code": "5121",
        "name": "Conturi la banci in lei",
    },
}
