"""
Delivery models for iiko.services API
"""

from pydantic import BaseModel, Field
from typing import List, Optional, Dict, Any
from datetime import datetime
from .common import Customer, Address, Coordinates


class DeliveryPoint(BaseModel):
    """Delivery point model"""
    address: Address = Field(..., description="Address")
    coordinates: Optional[Coordinates] = Field(None, description="Coordinates")
    comment: Optional[str] = Field(None, description="Comment")
    apartment: Optional[str] = Field(None, description="Apartment")
    entrance: Optional[str] = Field(None, description="Entrance")
    floor: Optional[str] = Field(None, description="Floor")
    doorphone: Optional[str] = Field(None, description="Doorphone")


class DeliveryCourier(BaseModel):
    """Delivery courier model"""
    id: str = Field(..., description="Courier ID")
    name: Optional[str] = Field(None, description="Courier name")
    phone: Optional[str] = Field(None, description="Courier phone")
    location: Optional[Coordinates] = Field(None, description="Courier location")
    is_active: Optional[bool] = Field(None, description="Is active")
    is_available: Optional[bool] = Field(None, description="Is available")
    is_on_shift: Optional[bool] = Field(None, description="Is on shift")
    is_free: Optional[bool] = Field(None, description="Is free")
    is_busy: Optional[bool] = Field(None, description="Is busy")
    is_on_delivery: Optional[bool] = Field(None, description="Is on delivery")
    is_on_way_back: Optional[bool] = Field(None, description="Is on way back")
    is_in_restaurant: Optional[bool] = Field(None, description="Is in restaurant")
    is_on_break: Optional[bool] = Field(None, description="Is on break")
    is_on_way_to_customer: Optional[bool] = Field(None, description="Is on way to customer")
    is_at_customer: Optional[bool] = Field(None, description="Is at customer")
    is_on_way_to_restaurant: Optional[bool] = Field(None, description="Is on way to restaurant")
    is_at_restaurant: Optional[bool] = Field(None, description="Is at restaurant")
    is_on_way_to_delivery_point: Optional[bool] = Field(None, description="Is on way to delivery point")
    is_at_delivery_point: Optional[bool] = Field(None, description="Is at delivery point")
    is_on_way_to_pickup_point: Optional[bool] = Field(None, description="Is on way to pickup point")
    is_at_pickup_point: Optional[bool] = Field(None, description="Is at pickup point")
    is_on_way_to_terminal_group: Optional[bool] = Field(None, description="Is on way to terminal group")
    is_at_terminal_group: Optional[bool] = Field(None, description="Is at terminal group")
    is_on_way_to_organization: Optional[bool] = Field(None, description="Is on way to organization")
    is_at_organization: Optional[bool] = Field(None, description="Is at organization")
    is_on_way_to_region: Optional[bool] = Field(None, description="Is on way to region")
    is_at_region: Optional[bool] = Field(None, description="Is at region")
    is_on_way_to_city: Optional[bool] = Field(None, description="Is on way to city")
    is_at_city: Optional[bool] = Field(None, description="Is at city")
    is_on_way_to_street: Optional[bool] = Field(None, description="Is on way to street")
    is_at_street: Optional[bool] = Field(None, description="Is at street")
    is_on_way_to_house: Optional[bool] = Field(None, description="Is on way to house")
    is_at_house: Optional[bool] = Field(None, description="Is at house")
    is_on_way_to_building: Optional[bool] = Field(None, description="Is on way to building")
    is_at_building: Optional[bool] = Field(None, description="Is at building")
    is_on_way_to_entrance: Optional[bool] = Field(None, description="Is on way to entrance")
    is_at_entrance: Optional[bool] = Field(None, description="Is at entrance")
    is_on_way_to_floor: Optional[bool] = Field(None, description="Is on way to floor")
    is_at_floor: Optional[bool] = Field(None, description="Is at floor")
    is_on_way_to_apartment: Optional[bool] = Field(None, description="Is on way to apartment")
    is_at_apartment: Optional[bool] = Field(None, description="Is at apartment")
    is_on_way_to_doorphone: Optional[bool] = Field(None, description="Is on way to doorphone")
    is_at_doorphone: Optional[bool] = Field(None, description="Is at doorphone")
    is_on_way_to_comment: Optional[bool] = Field(None, description="Is on way to comment")
    is_at_comment: Optional[bool] = Field(None, description="Is at comment")
    is_on_way_to_coordinates: Optional[bool] = Field(None, description="Is on way to coordinates")
    is_at_coordinates: Optional[bool] = Field(None, description="Is at coordinates")
    is_on_way_to_address: Optional[bool] = Field(None, description="Is on way to address")
    is_at_address: Optional[bool] = Field(None, description="Is at address")
    is_on_way_to_delivery: Optional[bool] = Field(None, description="Is on way to delivery")
    is_at_delivery: Optional[bool] = Field(None, description="Is at delivery")
    is_on_way_to_pickup: Optional[bool] = Field(None, description="Is on way to pickup")
    is_at_pickup: Optional[bool] = Field(None, description="Is at pickup")
    is_on_way_to_table_service: Optional[bool] = Field(None, description="Is on way to table service")
    is_at_table_service: Optional[bool] = Field(None, description="Is at table service")
    is_on_way_to_takeaway: Optional[bool] = Field(None, description="Is on way to takeaway")
    is_at_takeaway: Optional[bool] = Field(None, description="Is at takeaway")
    is_on_way_to_drive_through: Optional[bool] = Field(None, description="Is on way to drive through")
    is_at_drive_through: Optional[bool] = Field(None, description="Is at drive through")
    is_on_way_to_room_service: Optional[bool] = Field(None, description="Is on way to room service")
    is_at_room_service: Optional[bool] = Field(None, description="Is at room service")
    is_on_way_to_catering: Optional[bool] = Field(None, description="Is on way to catering")
    is_at_catering: Optional[bool] = Field(None, description="Is at catering")
    is_on_way_to_banquet: Optional[bool] = Field(None, description="Is on way to banquet")
    is_at_banquet: Optional[bool] = Field(None, description="Is at banquet")
    is_on_way_to_retail: Optional[bool] = Field(None, description="Is on way to retail")
    is_at_retail: Optional[bool] = Field(None, description="Is at retail")


class Delivery(BaseModel):
    """Delivery model"""
    id: Optional[str] = Field(None, description="Delivery ID")
    external_id: Optional[str] = Field(None, description="External ID")
    organization_id: str = Field(..., description="Organization ID")
    terminal_group_id: str = Field(..., description="Terminal group ID")
    customer: Optional[Customer] = Field(None, description="Customer")
    order_type_id: Optional[str] = Field(None, description="Order type ID")
    order_type_name: Optional[str] = Field(None, description="Order type name")
    order_service_type: Optional[str] = Field(None, description="Order service type")
    delivery_point: Optional[DeliveryPoint] = Field(None, description="Delivery point")
    courier: Optional[DeliveryCourier] = Field(None, description="Courier")
    status: Optional[str] = Field(None, description="Status")
    created_at: Optional[datetime] = Field(None, description="Created at")
    updated_at: Optional[datetime] = Field(None, description="Updated at")
    closed_at: Optional[datetime] = Field(None, description="Closed at")
    delivery_date: Optional[datetime] = Field(None, description="Delivery date")
    delivery_time_from: Optional[datetime] = Field(None, description="Delivery time from")
    delivery_time_to: Optional[datetime] = Field(None, description="Delivery time to")
    delivery_duration: Optional[int] = Field(None, description="Delivery duration")
    delivery_distance: Optional[float] = Field(None, description="Delivery distance")
    delivery_cost: Optional[float] = Field(None, description="Delivery cost")
    delivery_comment: Optional[str] = Field(None, description="Delivery comment")
    delivery_problem: Optional[str] = Field(None, description="Delivery problem")
    delivery_problem_comment: Optional[str] = Field(None, description="Delivery problem comment")
    delivery_problem_at: Optional[datetime] = Field(None, description="Delivery problem at")
    delivery_problem_resolved_at: Optional[datetime] = Field(None, description="Delivery problem resolved at")
    delivery_problem_resolved_by: Optional[str] = Field(None, description="Delivery problem resolved by")
    delivery_problem_resolved_comment: Optional[str] = Field(None, description="Delivery problem resolved comment")
    delivery_problem_resolved: Optional[bool] = Field(None, description="Delivery problem resolved")
    delivery_problem_resolution: Optional[str] = Field(None, description="Delivery problem resolution")
    delivery_problem_resolution_comment: Optional[str] = Field(None, description="Delivery problem resolution comment")
    delivery_problem_resolution_at: Optional[datetime] = Field(None, description="Delivery problem resolution at")
    delivery_problem_resolution_by: Optional[str] = Field(None, description="Delivery problem resolution by")
    delivery_problem_resolution_resolved: Optional[bool] = Field(None, description="Delivery problem resolution resolved")
    delivery_problem_resolution_resolved_at: Optional[datetime] = Field(None, description="Delivery problem resolution resolved at")
    delivery_problem_resolution_resolved_by: Optional[str] = Field(None, description="Delivery problem resolution resolved by")
    delivery_problem_resolution_resolved_comment: Optional[str] = Field(None, description="Delivery problem resolution resolved comment")
    is_delivery: Optional[bool] = Field(None, description="Is delivery")
    is_pickup: Optional[bool] = Field(None, description="Is pickup")
    is_table_service: Optional[bool] = Field(None, description="Is table service")
    is_takeaway: Optional[bool] = Field(None, description="Is takeaway")
    is_drive_through: Optional[bool] = Field(None, description="Is drive through")
    is_room_service: Optional[bool] = Field(None, description="Is room service")
    is_catering: Optional[bool] = Field(None, description="Is catering")
    is_banquet: Optional[bool] = Field(None, description="Is banquet")
    is_retail: Optional[bool] = Field(None, description="Is retail")
    is_external_food: Optional[bool] = Field(None, description="Is external food")
    is_external_beverages: Optional[bool] = Field(None, description="Is external beverages")
    is_external_alcohol: Optional[bool] = Field(None, description="Is external alcohol")
    is_external_service: Optional[bool] = Field(None, description="Is external service")
    is_external_goods: Optional[bool] = Field(None, description="Is external goods")
    is_external_tobacco: Optional[bool] = Field(None, description="Is external tobacco")
    is_external_hookah: Optional[bool] = Field(None, description="Is external hookah")
    is_external_other: Optional[bool] = Field(None, description="Is external other")
    is_external_delivery: Optional[bool] = Field(None, description="Is external delivery")
    is_external_pickup: Optional[bool] = Field(None, description="Is external pickup")
    is_external_table_service: Optional[bool] = Field(None, description="Is external table service")
    is_external_takeaway: Optional[bool] = Field(None, description="Is external takeaway")
    is_external_drive_through: Optional[bool] = Field(None, description="Is external drive through")
    is_external_room_service: Optional[bool] = Field(None, description="Is external room service")
    is_external_catering: Optional[bool] = Field(None, description="Is external catering")
    is_external_banquet: Optional[bool] = Field(None, description="Is external banquet")
    is_external_retail: Optional[bool] = Field(None, description="Is external retail")
    is_external_other_service: Optional[bool] = Field(None, description="Is external other service")
    is_external_other_goods: Optional[bool] = Field(None, description="Is external other goods")
    is_external_other_tobacco: Optional[bool] = Field(None, description="Is external other tobacco")
    is_external_other_hookah: Optional[bool] = Field(None, description="Is external other hookah")
    is_external_other_other: Optional[bool] = Field(None, description="Is external other other")


class DeliveryCreateRequest(BaseModel):
    """Request model for delivery creation"""
    organization_id: str = Field(..., description="Organization ID")
    terminal_group_id: str = Field(..., description="Terminal group ID")
    delivery: Delivery = Field(..., description="Delivery")


class DeliveryResponse(BaseModel):
    """Response model for delivery"""
    delivery_id: str = Field(..., description="Delivery ID")
    delivery_number: Optional[str] = Field(None, description="Delivery number")
    delivery_external_number: Optional[str] = Field(None, description="Delivery external number")
    delivery_sum: Optional[float] = Field(None, description="Delivery sum")
    delivery_status: Optional[str] = Field(None, description="Delivery status")
    delivery_created_at: Optional[datetime] = Field(None, description="Delivery created at")
    delivery_updated_at: Optional[datetime] = Field(None, description="Delivery updated at")
    delivery_closed_at: Optional[datetime] = Field(None, description="Delivery closed at")
    delivery_problem: Optional[str] = Field(None, description="Delivery problem")
    delivery_comment: Optional[str] = Field(None, description="Delivery comment")
    delivery_is_deleted: Optional[bool] = Field(None, description="Delivery is deleted")
    delivery_is_draft: Optional[bool] = Field(None, description="Delivery is draft")
    delivery_is_external: Optional[bool] = Field(None, description="Delivery is external")
    delivery_is_fiscalized: Optional[bool] = Field(None, description="Delivery is fiscalized")
    delivery_is_paid: Optional[bool] = Field(None, description="Delivery is paid")
    delivery_is_printed: Optional[bool] = Field(None, description="Delivery is printed")
    delivery_is_service_charge_included: Optional[bool] = Field(None, description="Delivery is service charge included")
    delivery_is_vat_included: Optional[bool] = Field(None, description="Delivery is VAT included")
    delivery_is_verified: Optional[bool] = Field(None, description="Delivery is verified")
    delivery_is_waiting: Optional[bool] = Field(None, description="Delivery is waiting")
    delivery_is_web: Optional[bool] = Field(None, description="Delivery is web")
    delivery_is_pickup: Optional[bool] = Field(None, description="Delivery is pickup")
    delivery_is_delivery: Optional[bool] = Field(None, description="Delivery is delivery")
    delivery_is_table_service: Optional[bool] = Field(None, description="Delivery is table service")
    delivery_is_takeaway: Optional[bool] = Field(None, description="Delivery is takeaway")
    delivery_is_drive_through: Optional[bool] = Field(None, description="Delivery is drive through")
    delivery_is_room_service: Optional[bool] = Field(None, description="Delivery is room service")
    delivery_is_catering: Optional[bool] = Field(None, description="Delivery is catering")
    delivery_is_banquet: Optional[bool] = Field(None, description="Delivery is banquet")
    delivery_is_retail: Optional[bool] = Field(None, description="Delivery is retail")
    delivery_is_external_food: Optional[bool] = Field(None, description="Delivery is external food")
    delivery_is_external_beverages: Optional[bool] = Field(None, description="Delivery is external beverages")
    delivery_is_external_alcohol: Optional[bool] = Field(None, description="Delivery is external alcohol")
    delivery_is_external_service: Optional[bool] = Field(None, description="Delivery is external service")
    delivery_is_external_goods: Optional[bool] = Field(None, description="Delivery is external goods")
    delivery_is_external_tobacco: Optional[bool] = Field(None, description="Delivery is external tobacco")
    delivery_is_external_hookah: Optional[bool] = Field(None, description="Delivery is external hookah")
    delivery_is_external_other: Optional[bool] = Field(None, description="Delivery is external other")
    delivery_is_external_delivery: Optional[bool] = Field(None, description="Delivery is external delivery")
    delivery_is_external_pickup: Optional[bool] = Field(None, description="Delivery is external pickup")
    delivery_is_external_table_service: Optional[bool] = Field(None, description="Delivery is external table service")
    delivery_is_external_takeaway: Optional[bool] = Field(None, description="Delivery is external takeaway")
    delivery_is_external_drive_through: Optional[bool] = Field(None, description="Delivery is external drive through")
    delivery_is_external_room_service: Optional[bool] = Field(None, description="Delivery is external room service")
    delivery_is_external_catering: Optional[bool] = Field(None, description="Delivery is external catering")
    delivery_is_external_banquet: Optional[bool] = Field(None, description="Delivery is external banquet")
    delivery_is_external_retail: Optional[bool] = Field(None, description="Delivery is external retail")
    delivery_is_external_other_service: Optional[bool] = Field(None, description="Delivery is external other service")
    delivery_is_external_other_goods: Optional[bool] = Field(None, description="Delivery is external other goods")
    delivery_is_external_other_tobacco: Optional[bool] = Field(None, description="Delivery is external other tobacco")
    delivery_is_external_other_hookah: Optional[bool] = Field(None, description="Delivery is external other hookah")
    delivery_is_external_other_other: Optional[bool] = Field(None, description="Delivery is external other other")


class DeliveryByIdRequest(BaseModel):
    """Request model for delivery by ID"""
    organization_ids: List[str] = Field(..., description="Organization IDs")
    delivery_ids: List[str] = Field(..., description="Delivery IDs")


class DeliveryByIdResponse(BaseModel):
    """Response model for delivery by ID"""
    deliveries: List[Delivery] = Field(..., description="Deliveries")
