#/apps/aroflo_connector_app/zones/registry.py
from __future__ import annotations

from typing import Dict, List, Any

#from .lastupdate import LastUpdateZone
from .users import UsersZone
from .permissiongroups import PermissionGroupsZone
from .userpositions import UserPositionsZone
from .businessunits import BusinessUnitsZone

#from .invoices import InvoicesZone
#from .clients import ClientsZone
from .timesheets import TimesheetsZone
from .tasks import TasksZone
from .overheads import OverheadsZone
from .trackingcentres import TrackingCentresZone





# from .clients import ClientsZone   # ⬅️ COMENTADO HASTA IMPLEMENTARLA


def build_registry(client: Any) -> Dict[str, Any]:
    """
    Crea el registro de zonas para un cliente AroFlo concreto.
    De momento solo LastUpdate y Users.
    """
    zones: Dict[str, Any] = {
        #"lastupdate": LastUpdateZone(client),
        "users": UsersZone(client),
        "permissiongroups": PermissionGroupsZone(client),
        "userpositions" : UserPositionsZone(client),
        "businessunits": BusinessUnitsZone(client),
        #"invoices": InvoicesZone(client),
        #"clients": ClientsZone(client),
        "timesheets": TimesheetsZone(client),
        "tasks": TasksZone(client),
        "overheads": OverheadsZone(client),
        "trackingcentres": TrackingCentresZone(client),

  
        
    }
    return zones


def list_zones_metadata(client: Any) -> List[dict]:
    registry = build_registry(client)
    return [zone.to_dict() for zone in registry.values()]


def get_zone(client: Any, code: str):
    registry = build_registry(client)
    try:
        return registry[code]
    except KeyError:
        raise KeyError(f"Zona '{code}' no está registrada")

