from dataclasses import dataclass, asdict
from typing import Optional, Dict, Any, List


class AbnLookupError(Exception):
    """Error de alto nivel para la app de ABN Lookup v1."""
    pass


@dataclass
class AddressV1:
    line1: str = ""
    line2: str = ""
    line3: str = ""
    line4: str = ""
    suburb: str = ""
    state_code: str = ""
    postcode: str = ""
    country_code: str = ""

    def to_dict(self) -> Dict[str, Any]:
        return asdict(self)


@dataclass
class AbnRecordV1:
    # Identificadores
    abn: str
    acn: Optional[str]

    # Nombres
    main_name: str
    legal_name: str
    business_names: List[str]

    # Estado de ABN
    status_code: str
    status_from: str

    # Tipo de entidad
    entity_type_code: str
    entity_type_desc: str

    # Direcciones
    main_business_address: AddressV1
    postal_address: AddressV1

    # GST
    gst_registered: bool
    gst_effective_from: Optional[str] = None
    gst_effective_to: Optional[str] = None

    # Metadatos
    last_updated_date: Optional[str] = None

    def to_dict(self) -> Dict[str, Any]:
        """
        Convierte todo el registro (incluyendo direcciones) a un dict JSON-friendly.
        """
        return asdict(self)

