"""Customer and connection schemas.

Customers are not created directly — they appear when an application reaches
`installed`. These schemas exist so other modules (equipment hand-outs, complaints)
can look a customer up and attach to one of their connections.
"""
from datetime import date
from decimal import Decimal

from pydantic import BaseModel, ConfigDict

from app.models.enums import ConnectionStatus
from app.schemas.reference import AreaWithZoneOut
from app.schemas.types import DhakaDateTime


class CustomerBrief(BaseModel):
    """Minimal identity, embedded wherever a customer is referenced."""

    model_config = ConfigDict(from_attributes=True)

    id: int
    customer_code: str
    full_name: str
    phone: str


class ConnectionBrief(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    connection_code: str
    status: ConnectionStatus
    activated_on: date


class ConnectionWithCustomer(ConnectionBrief):
    """A connection carrying enough of its customer to render a row without a second call."""

    customer: CustomerBrief
    area: AreaWithZoneOut


class ConnectionOut(ConnectionWithCustomer):
    monthly_bill: Decimal | None
    terminated_on: date | None
    created_at: DhakaDateTime


class CustomerListItem(CustomerBrief):
    address: str
    area: AreaWithZoneOut
    created_at: DhakaDateTime


class CustomerDetail(CustomerListItem):
    alt_phone: str | None
    nid: str | None
    email: str | None
    updated_at: DhakaDateTime
    connections: list[ConnectionBrief]
