from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime
from uuid import UUID
from decimal import Decimal
from .base_responses import BaseResponse, CrudCollection


class BuildAreaListResponse(BaseResponse):
    """Response model for building area list endpoint"""

    uu_id: UUID
    build_id: int
    build_uu_id: str
    area_name: str
    area_value: float
    created_at: datetime
    updated_at: Optional[datetime]
    deleted: bool = False


class BuildAreaListCollection(CrudCollection[BuildAreaListResponse]):
    """Collection of building area list"""

    pass


class BuildSitesListResponse(BaseResponse):
    """Response model for building sites list endpoint"""

    uu_id: UUID
    address_id: int
    site_name: str
    site_value: float
    created_at: datetime
    updated_at: Optional[datetime]
    deleted: bool = False


class BuildSitesListCollection(CrudCollection[BuildSitesListResponse]):
    """Collection of building sites list"""

    pass


class BuildTypesListResponse(BaseResponse):
    """Response model for building types list endpoint"""

    uu_id: UUID
    type_name: str
    type_value: str
    created_at: datetime
    updated_at: Optional[datetime]
    deleted: bool = False


class BuildTypesListCollection(CrudCollection[BuildTypesListResponse]):
    """Collection of building types list"""

    pass


class BuildTypesResponse(BaseResponse):
    """Response model for building types"""

    function_code: str
    type_code: str
    lang: str = "TR"


class BuildTypesCollection(CrudCollection[BuildTypesResponse]):
    """Collection of building types"""

    pass


class Part2EmployeeResponse(BaseResponse):
    """Response model for part to employee mapping"""

    build_id: int
    part_id: int
    employee_id: int


class Part2EmployeeCollection(CrudCollection[Part2EmployeeResponse]):
    """Collection of part to employee mappings"""

    pass


class RelationshipEmployee2BuildResponse(BaseResponse):
    """Response model for employee to build relationship"""

    company_id: int
    employee_id: int
    member_id: int
    relationship_type: Optional[str] = "Employee"
    show_only: bool = False


class RelationshipEmployee2BuildCollection(
    CrudCollection[RelationshipEmployee2BuildResponse]
):
    """Collection of employee to build relationships"""

    pass


class BuildResponse(BaseResponse):
    """Response model for buildings"""

    gov_address_code: str = ""
    build_name: str
    build_no: str
    max_floor: int = 1
    underground_floor: int = 0
    build_date: datetime
    decision_period_date: datetime
    tax_no: str = ""
    lift_count: int = 0
    heating_system: bool = True
    cooling_system: bool = False
    hot_water_system: bool = False
    block_service_man_count: int = 0
    security_service_man_count: int = 0
    garage_count: int = 0
    management_room_id: Optional[int]
    site_id: Optional[int]
    site_uu_id: Optional[str]
    address_id: int
    address_uu_id: str
    build_types_id: int
    build_types_uu_id: Optional[str]


class BuildCollection(CrudCollection[BuildResponse]):
    """Collection of buildings"""

    pass


class BuildPartsResponse(BaseResponse):
    """Response model for building parts"""

    address_gov_code: str
    part_no: int = 0
    part_level: int = 0
    part_code: str
    part_gross_size: int = 0
    part_net_size: int = 0
    default_accessory: str = "0"
    human_livable: bool = True
    due_part_key: str
    build_id: int
    build_uu_id: str
    part_direction_id: Optional[int]
    part_direction_uu_id: Optional[str]
    part_type_id: int
    part_type_uu_id: str


class BuildPartsCollection(CrudCollection[BuildPartsResponse]):
    """Collection of building parts"""

    pass


class BuildLivingSpaceResponse(BaseResponse):
    """Response model for building living space"""

    fix_value: Decimal = Decimal("0")
    fix_percent: Decimal = Decimal("0")
    agreement_no: str = ""
    marketing_process: bool = False
    marketing_layer: int = 0
    build_parts_id: int
    build_parts_uu_id: str
    person_id: int
    person_uu_id: str
    occupant_type: int
    occupant_type_uu_id: str


class BuildLivingSpaceCollection(CrudCollection[BuildLivingSpaceResponse]):
    """Collection of building living spaces"""

    pass


class BuildManagementResponse(BaseResponse):
    """Response model for building management"""

    discounted_percentage: Decimal = Decimal("0.00")
    discounted_price: Decimal = Decimal("0.00")
    calculated_price: Decimal = Decimal("0.00")
    occupant_type: int
    occupant_type_uu_id: str
    build_id: int
    build_uu_id: str
    build_parts_id: int
    build_parts_uu_id: str


class BuildManagementCollection(CrudCollection[BuildManagementResponse]):
    """Collection of building management records"""

    pass


class BuildAreaResponse(BaseResponse):
    """Response model for building area"""

    area_name: str = ""
    area_code: str = ""
    area_type: str = "GREEN"
    area_direction: str = "NN"
    area_gross_size: Decimal = Decimal("0")
    area_net_size: Decimal = Decimal("0")
    width: int = 0
    size: int = 0
    build_id: int
    build_uu_id: str
    part_type_id: Optional[int]
    part_type_uu_id: Optional[str]


class BuildAreaCollection(CrudCollection[BuildAreaResponse]):
    """Collection of building areas"""

    pass


class BuildSitesResponse(BaseResponse):
    """Response model for building sites"""

    site_name: str
    site_no: str
    address_id: int
    address_uu_id: Optional[str]


class BuildSitesCollection(CrudCollection[BuildSitesResponse]):
    """Collection of building sites"""

    pass


class BuildCompaniesProvidingResponse(BaseResponse):
    """Response model for building companies providing services"""

    build_id: int
    build_uu_id: Optional[str]
    company_id: int
    company_uu_id: Optional[str]
    provide_id: Optional[int]
    provide_uu_id: Optional[str]
    contract_id: Optional[int]


class BuildCompaniesProvidingCollection(
    CrudCollection[BuildCompaniesProvidingResponse]
):
    """Collection of building companies providing services"""

    pass


class BuildPersonProvidingResponse(BaseResponse):
    """Response model for building person providing services"""

    build_id: int
    build_uu_id: Optional[str]
    people_id: int
    people_uu_id: Optional[str]
    provide_id: Optional[int]
    provide_uu_id: Optional[str]
    contract_id: Optional[int]


class BuildPersonProvidingCollection(CrudCollection[BuildPersonProvidingResponse]):
    """Collection of building person providing services"""

    pass
