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 BuildDecisionBookResponse(BaseResponse):
    """Response model for building decision book"""

    decision_book_pdf_path: Optional[str] = ""
    resp_company_fix_wage: float = 0
    contact_agreement_path: Optional[str] = ""
    contact_agreement_date: Optional[datetime]
    meeting_date: Optional[str]
    decision_type: Optional[str]


class BuildDecisionBookCollection(CrudCollection[BuildDecisionBookResponse]):
    """Collection of building decision books"""

    pass


class BuildDecisionBookInvitationsResponse(BaseResponse):
    """Response model for building decision book invitations"""

    build_id: int
    build_uu_id: Optional[str]
    decision_book_id: int
    decision_book_uu_id: Optional[str]
    invitation_type: str
    invitation_attempt: int = 1
    living_part_count: int = 1
    living_part_percentage: Decimal = Decimal("0.51")
    message: Optional[str]
    planned_date: datetime
    planned_date_expires: datetime


class BuildDecisionBookInvitationsCollection(
    CrudCollection[BuildDecisionBookInvitationsResponse]
):
    """Collection of building decision book invitations"""

    pass


class BuildDecisionBookPersonResponse(BaseResponse):
    """Response model for building decision book person"""

    dues_percent_discount: int = 0
    dues_fix_discount: Decimal = Decimal("0")
    dues_discount_approval_date: datetime
    send_date: datetime
    is_attending: bool = False
    confirmed_date: Optional[datetime]
    token: str = ""
    vicarious_person_id: Optional[int]
    vicarious_person_uu_id: Optional[str]
    invite_id: int
    invite_uu_id: str
    build_decision_book_id: int
    build_decision_book_uu_id: str
    build_living_space_id: int
    build_living_space_uu_id: Optional[str]
    person_id: int


class BuildDecisionBookPersonCollection(
    CrudCollection[BuildDecisionBookPersonResponse]
):
    """Collection of building decision book persons"""

    pass


class BuildDecisionBookPersonOccupantsResponse(BaseResponse):
    """Response model for building decision book person occupants"""

    build_decision_book_person_id: int
    build_decision_book_person_uu_id: Optional[str]
    invite_id: Optional[int]
    invite_uu_id: Optional[str]
    occupant_type_id: int
    occupant_type_uu_id: Optional[str]


class BuildDecisionBookPersonOccupantsCollection(
    CrudCollection[BuildDecisionBookPersonOccupantsResponse]
):
    """Collection of building decision book person occupants"""

    pass


class BuildDecisionBookItemsResponse(BaseResponse):
    """Response model for building decision book items"""

    item_order: int
    item_comment: str
    item_objection: Optional[str]
    info_is_completed: bool = False
    is_payment_created: bool = False
    info_type_id: Optional[int]
    info_type_uu_id: Optional[str]
    build_decision_book_id: int
    build_decision_book_uu_id: Optional[str]
    item_short_comment: Optional[str]


class BuildDecisionBookItemsCollection(CrudCollection[BuildDecisionBookItemsResponse]):
    """Collection of building decision book items"""

    pass


class BuildDecisionBookItemsUnapprovedResponse(BaseResponse):
    """Response model for building decision book items unapproved"""

    item_objection: str
    item_order: int
    decision_book_item_id: int
    decision_book_item_uu_id: Optional[str]
    person_id: int
    person_uu_id: Optional[str]
    build_decision_book_item: int
    build_decision_book_item_uu_id: Optional[str]


class BuildDecisionBookItemsUnapprovedCollection(
    CrudCollection[BuildDecisionBookItemsUnapprovedResponse]
):
    """Collection of building decision book items unapproved"""

    pass


class BuildDecisionBookPaymentsResponse(BaseResponse):
    """Response model for building decision book payments"""

    payment_plan_time_periods: str
    process_date: datetime
    payment_amount: Decimal
    currency: str = "TRY"
    payment_types_id: Optional[int]
    payment_types_uu_id: Optional[str]
    period_time: str
    process_date_y: int
    process_date_m: int
    build_decision_book_item_id: int
    build_decision_book_item_uu_id: str
    build_parts_id: int
    build_parts_uu_id: str
    decision_book_project_id: Optional[int]
    decision_book_project_uu_id: Optional[str]
    account_records_id: Optional[int]
    account_records_uu_id: Optional[str]


class BuildDecisionBookPaymentsCollection(
    CrudCollection[BuildDecisionBookPaymentsResponse]
):
    """Collection of building decision book payments"""

    pass


class BuildDecisionBookLegalResponse(BaseResponse):
    """Response model for building decision book legal"""

    period_start_date: datetime
    lawsuits_decision_number: str
    lawsuits_decision_date: datetime
    period_stop_date: datetime
    decision_book_pdf_path: Optional[str] = ""
    resp_company_total_wage: Optional[Decimal] = Decimal("0")
    contact_agreement_path: Optional[str] = ""
    contact_agreement_date: Optional[datetime]
    meeting_date: str
    lawsuits_type: str = "C"
    lawsuits_name: str
    lawsuits_note: str
    lawyer_cost: Decimal
    mediator_lawyer_cost: Decimal
    other_cost: Decimal
    legal_cost: Decimal
    approved_cost: Decimal
    total_price: Decimal
    build_db_item_id: int
    build_db_item_uu_id: Optional[str]
    resp_attorney_id: int
    resp_attorney_uu_id: Optional[str]
    resp_attorney_company_id: int
    resp_attorney_company_uu_id: Optional[str]
    mediator_lawyer_person_id: int
    mediator_lawyer_person_uu_id: Optional[str]


class BuildDecisionBookLegalCollection(CrudCollection[BuildDecisionBookLegalResponse]):
    """Collection of building decision book legal records"""

    pass
