"""
Order 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


class OrderItemModifier(BaseModel):
    """Order item modifier model"""
    id: str = Field(..., description="Modifier ID")
    name: Optional[str] = Field(None, description="Modifier name")
    amount: float = Field(..., description="Amount")
    product_id: Optional[str] = Field(None, description="Product ID")
    price: Optional[float] = Field(None, description="Price")
    sum: Optional[float] = Field(None, description="Sum")
    group_id: Optional[str] = Field(None, description="Group ID")
    group_name: Optional[str] = Field(None, description="Group name")


class OrderItem(BaseModel):
    """Order item model"""
    id: Optional[str] = Field(None, description="Item ID")
    product_id: str = Field(..., description="Product ID")
    name: Optional[str] = Field(None, description="Product name")
    amount: float = Field(..., description="Amount")
    price: Optional[float] = Field(None, description="Price")
    sum: Optional[float] = Field(None, description="Sum")
    comment: Optional[str] = Field(None, description="Comment")
    modifiers: Optional[List[OrderItemModifier]] = Field(None, description="Modifiers")
    size_id: Optional[str] = Field(None, description="Size ID")
    size_name: Optional[str] = Field(None, description="Size name")
    type: Optional[str] = Field(None, description="Type")
    status: Optional[str] = Field(None, description="Status")
    deleted: Optional[bool] = Field(None, description="Deleted")
    deleted_reason: Optional[str] = Field(None, description="Deleted reason")
    position_id: Optional[str] = Field(None, description="Position ID")


class OrderPayment(BaseModel):
    """Order payment model"""
    payment_type_id: str = Field(..., description="Payment type ID")
    payment_type_name: Optional[str] = Field(None, description="Payment type name")
    sum: float = Field(..., description="Sum")
    payment_type_kind: Optional[str] = Field(None, description="Payment type kind")
    is_processed: Optional[bool] = Field(None, description="Is processed")
    is_fiscal: Optional[bool] = Field(None, description="Is fiscal")
    is_prepay: Optional[bool] = Field(None, description="Is prepay")


class OrderDiscount(BaseModel):
    """Order discount model"""
    discount_id: str = Field(..., description="Discount ID")
    discount_name: Optional[str] = Field(None, description="Discount name")
    sum: float = Field(..., description="Sum")
    discount_type: Optional[str] = Field(None, description="Discount type")
    is_manual: Optional[bool] = Field(None, description="Is manual")
    comment: Optional[str] = Field(None, description="Comment")


class Order(BaseModel):
    """Order model"""
    id: Optional[str] = Field(None, description="Order 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_items: List[OrderItem] = Field(..., description="Order items")
    payments: Optional[List[OrderPayment]] = Field(None, description="Payments")
    discounts: Optional[List[OrderDiscount]] = Field(None, description="Discounts")
    comment: Optional[str] = Field(None, description="Comment")
    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")
    sum: Optional[float] = Field(None, description="Sum")
    number: Optional[str] = Field(None, description="Number")
    source_key: Optional[str] = Field(None, description="Source key")
    problem: Optional[str] = Field(None, description="Problem")
    conception_id: Optional[str] = Field(None, description="Conception ID")
    table_id: Optional[str] = Field(None, description="Table ID")
    table_name: Optional[str] = Field(None, description="Table name")
    guest_count: Optional[int] = Field(None, description="Guest count")
    is_fast_food: Optional[bool] = Field(None, description="Is fast food")
    is_deleted: Optional[bool] = Field(None, description="Is deleted")
    is_draft: Optional[bool] = Field(None, description="Is draft")
    is_external: Optional[bool] = Field(None, description="Is external")
    is_fiscalized: Optional[bool] = Field(None, description="Is fiscalized")
    is_paid: Optional[bool] = Field(None, description="Is paid")
    is_printed: Optional[bool] = Field(None, description="Is printed")
    is_service_charge_included: Optional[bool] = Field(None, description="Is service charge included")
    is_vat_included: Optional[bool] = Field(None, description="Is VAT included")
    is_verified: Optional[bool] = Field(None, description="Is verified")
    is_waiting: Optional[bool] = Field(None, description="Is waiting")
    is_web: Optional[bool] = Field(None, description="Is web")
    is_pickup: Optional[bool] = Field(None, description="Is pickup")
    is_delivery: Optional[bool] = Field(None, description="Is delivery")
    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")
    is_external_other_delivery: Optional[bool] = Field(None, description="Is external other delivery")
    is_external_other_pickup: Optional[bool] = Field(None, description="Is external other pickup")
    is_external_other_table_service: Optional[bool] = Field(None, description="Is external other table service")
    is_external_other_takeaway: Optional[bool] = Field(None, description="Is external other takeaway")
    is_external_other_drive_through: Optional[bool] = Field(None, description="Is external other drive through")
    is_external_other_room_service: Optional[bool] = Field(None, description="Is external other room service")
    is_external_other_catering: Optional[bool] = Field(None, description="Is external other catering")
    is_external_other_banquet: Optional[bool] = Field(None, description="Is external other banquet")
    is_external_other_retail: Optional[bool] = Field(None, description="Is external other retail")
    is_external_other_other_service: Optional[bool] = Field(None, description="Is external other other service")
    is_external_other_other_goods: Optional[bool] = Field(None, description="Is external other other goods")
    is_external_other_other_tobacco: Optional[bool] = Field(None, description="Is external other other tobacco")
    is_external_other_other_hookah: Optional[bool] = Field(None, description="Is external other other hookah")
    is_external_other_other_other: Optional[bool] = Field(None, description="Is external other other other")
    is_external_other_other_delivery: Optional[bool] = Field(None, description="Is external other other delivery")
    is_external_other_other_pickup: Optional[bool] = Field(None, description="Is external other other pickup")
    is_external_other_other_table_service: Optional[bool] = Field(None, description="Is external other other table service")
    is_external_other_other_takeaway: Optional[bool] = Field(None, description="Is external other other takeaway")
    is_external_other_other_drive_through: Optional[bool] = Field(None, description="Is external other other drive through")
    is_external_other_other_room_service: Optional[bool] = Field(None, description="Is external other other room service")
    is_external_other_other_catering: Optional[bool] = Field(None, description="Is external other other catering")
    is_external_other_other_banquet: Optional[bool] = Field(None, description="Is external other other banquet")
    is_external_other_other_retail: Optional[bool] = Field(None, description="Is external other other retail")
    is_external_other_other_other_service: Optional[bool] = Field(None, description="Is external other other other service")
    is_external_other_other_other_goods: Optional[bool] = Field(None, description="Is external other other other goods")
    is_external_other_other_other_tobacco: Optional[bool] = Field(None, description="Is external other other other tobacco")
    is_external_other_other_other_hookah: Optional[bool] = Field(None, description="Is external other other other hookah")
    is_external_other_other_other_other: Optional[bool] = Field(None, description="Is external other other other other")
    is_external_other_other_other_delivery: Optional[bool] = Field(None, description="Is external other other other delivery")
    is_external_other_other_other_pickup: Optional[bool] = Field(None, description="Is external other other other pickup")
    is_external_other_other_other_table_service: Optional[bool] = Field(None, description="Is external other other other table service")
    is_external_other_other_other_takeaway: Optional[bool] = Field(None, description="Is external other other other takeaway")
    is_external_other_other_other_drive_through: Optional[bool] = Field(None, description="Is external other other other drive through")
    is_external_other_other_other_room_service: Optional[bool] = Field(None, description="Is external other other other room service")
    is_external_other_other_other_catering: Optional[bool] = Field(None, description="Is external other other other catering")
    is_external_other_other_other_banquet: Optional[bool] = Field(None, description="Is external other other other banquet")
    is_external_other_other_other_retail: Optional[bool] = Field(None, description="Is external other other other retail")
    is_external_other_other_other_other_service: Optional[bool] = Field(None, description="Is external other other other other service")
    is_external_other_other_other_other_goods: Optional[bool] = Field(None, description="Is external other other other other goods")
    is_external_other_other_other_other_tobacco: Optional[bool] = Field(None, description="Is external other other other other tobacco")
    is_external_other_other_other_other_hookah: Optional[bool] = Field(None, description="Is external other other other other hookah")
    is_external_other_other_other_other_other: Optional[bool] = Field(None, description="Is external other other other other other")
    is_external_other_other_other_other_delivery: Optional[bool] = Field(None, description="Is external other other other other delivery")
    is_external_other_other_other_other_pickup: Optional[bool] = Field(None, description="Is external other other other other pickup")
    is_external_other_other_other_other_table_service: Optional[bool] = Field(None, description="Is external other other other other table service")
    is_external_other_other_other_other_takeaway: Optional[bool] = Field(None, description="Is external other other other other takeaway")
    is_external_other_other_other_other_drive_through: Optional[bool] = Field(None, description="Is external other other other other drive through")
    is_external_other_other_other_other_room_service: Optional[bool] = Field(None, description="Is external other other other other room service")
    is_external_other_other_other_other_catering: Optional[bool] = Field(None, description="Is external other other other other catering")
    is_external_other_other_other_other_banquet: Optional[bool] = Field(None, description="Is external other other other other banquet")
    is_external_other_other_other_other_retail: Optional[bool] = Field(None, description="Is external other other other other retail")


class OrderCreateRequest(BaseModel):
    """Request model for order creation"""
    organization_id: str = Field(..., description="Organization ID")
    terminal_group_id: str = Field(..., description="Terminal group ID")
    order: Order = Field(..., description="Order")


class OrderResponse(BaseModel):
    """Response model for order"""
    order_id: str = Field(..., description="Order ID")
    order_number: Optional[str] = Field(None, description="Order number")
    order_external_number: Optional[str] = Field(None, description="Order external number")
    order_sum: Optional[float] = Field(None, description="Order sum")
    order_status: Optional[str] = Field(None, description="Order status")
    order_created_at: Optional[datetime] = Field(None, description="Order created at")
    order_updated_at: Optional[datetime] = Field(None, description="Order updated at")
    order_closed_at: Optional[datetime] = Field(None, description="Order closed at")
    order_problem: Optional[str] = Field(None, description="Order problem")
    order_comment: Optional[str] = Field(None, description="Order comment")
    order_is_deleted: Optional[bool] = Field(None, description="Order is deleted")
    order_is_draft: Optional[bool] = Field(None, description="Order is draft")
    order_is_external: Optional[bool] = Field(None, description="Order is external")
    order_is_fiscalized: Optional[bool] = Field(None, description="Order is fiscalized")
    order_is_paid: Optional[bool] = Field(None, description="Order is paid")
    order_is_printed: Optional[bool] = Field(None, description="Order is printed")
    order_is_service_charge_included: Optional[bool] = Field(None, description="Order is service charge included")
    order_is_vat_included: Optional[bool] = Field(None, description="Order is VAT included")
    order_is_verified: Optional[bool] = Field(None, description="Order is verified")
    order_is_waiting: Optional[bool] = Field(None, description="Order is waiting")
    order_is_web: Optional[bool] = Field(None, description="Order is web")
    order_is_pickup: Optional[bool] = Field(None, description="Order is pickup")
    order_is_delivery: Optional[bool] = Field(None, description="Order is delivery")
    order_is_table_service: Optional[bool] = Field(None, description="Order is table service")
    order_is_takeaway: Optional[bool] = Field(None, description="Order is takeaway")
    order_is_drive_through: Optional[bool] = Field(None, description="Order is drive through")
    order_is_room_service: Optional[bool] = Field(None, description="Order is room service")
    order_is_catering: Optional[bool] = Field(None, description="Order is catering")
    order_is_banquet: Optional[bool] = Field(None, description="Order is banquet")
    order_is_retail: Optional[bool] = Field(None, description="Order is retail")
    order_is_external_food: Optional[bool] = Field(None, description="Order is external food")
    order_is_external_beverages: Optional[bool] = Field(None, description="Order is external beverages")
    order_is_external_alcohol: Optional[bool] = Field(None, description="Order is external alcohol")
    order_is_external_service: Optional[bool] = Field(None, description="Order is external service")
    order_is_external_goods: Optional[bool] = Field(None, description="Order is external goods")
    order_is_external_tobacco: Optional[bool] = Field(None, description="Order is external tobacco")
    order_is_external_hookah: Optional[bool] = Field(None, description="Order is external hookah")
    order_is_external_other: Optional[bool] = Field(None, description="Order is external other")
    order_is_external_delivery: Optional[bool] = Field(None, description="Order is external delivery")
    order_is_external_pickup: Optional[bool] = Field(None, description="Order is external pickup")
    order_is_external_table_service: Optional[bool] = Field(None, description="Order is external table service")
    order_is_external_takeaway: Optional[bool] = Field(None, description="Order is external takeaway")
    order_is_external_drive_through: Optional[bool] = Field(None, description="Order is external drive through")
    order_is_external_room_service: Optional[bool] = Field(None, description="Order is external room service")
    order_is_external_catering: Optional[bool] = Field(None, description="Order is external catering")
    order_is_external_banquet: Optional[bool] = Field(None, description="Order is external banquet")
    order_is_external_retail: Optional[bool] = Field(None, description="Order is external retail")
    order_is_external_other_service: Optional[bool] = Field(None, description="Order is external other service")
    order_is_external_other_goods: Optional[bool] = Field(None, description="Order is external other goods")
    order_is_external_other_tobacco: Optional[bool] = Field(None, description="Order is external other tobacco")
    order_is_external_other_hookah: Optional[bool] = Field(None, description="Order is external other hookah")
    order_is_external_other_other: Optional[bool] = Field(None, description="Order is external other other")
    order_is_external_other_delivery: Optional[bool] = Field(None, description="Order is external other delivery")
    order_is_external_other_pickup: Optional[bool] = Field(None, description="Order is external other pickup")
    order_is_external_other_table_service: Optional[bool] = Field(None, description="Order is external other table service")
    order_is_external_other_takeaway: Optional[bool] = Field(None, description="Order is external other takeaway")
    order_is_external_other_drive_through: Optional[bool] = Field(None, description="Order is external other drive through")
    order_is_external_other_room_service: Optional[bool] = Field(None, description="Order is external other room service")
    order_is_external_other_catering: Optional[bool] = Field(None, description="Order is external other catering")
    order_is_external_other_banquet: Optional[bool] = Field(None, description="Order is external other banquet")
    order_is_external_other_retail: Optional[bool] = Field(None, description="Order is external other retail")
    order_is_external_other_other_service: Optional[bool] = Field(None, description="Order is external other other service")
    order_is_external_other_other_goods: Optional[bool] = Field(None, description="Order is external other other goods")
    order_is_external_other_other_tobacco: Optional[bool] = Field(None, description="Order is external other other tobacco")
    order_is_external_other_other_hookah: Optional[bool] = Field(None, description="Order is external other other hookah")
    order_is_external_other_other_other: Optional[bool] = Field(None, description="Order is external other other other")
    order_is_external_other_other_delivery: Optional[bool] = Field(None, description="Order is external other other delivery")
    order_is_external_other_other_pickup: Optional[bool] = Field(None, description="Order is external other other pickup")
    order_is_external_other_other_table_service: Optional[bool] = Field(None, description="Order is external other other table service")
    order_is_external_other_other_takeaway: Optional[bool] = Field(None, description="Order is external other other takeaway")
    order_is_external_other_other_drive_through: Optional[bool] = Field(None, description="Order is external other other drive through")
    order_is_external_other_other_room_service: Optional[bool] = Field(None, description="Order is external other other room service")
    order_is_external_other_other_catering: Optional[bool] = Field(None, description="Order is external other other catering")
    order_is_external_other_other_banquet: Optional[bool] = Field(None, description="Order is external other other banquet")
    order_is_external_other_other_retail: Optional[bool] = Field(None, description="Order is external other other retail")
    order_is_external_other_other_other_service: Optional[bool] = Field(None, description="Order is external other other other service")
    order_is_external_other_other_other_goods: Optional[bool] = Field(None, description="Order is external other other other goods")
    order_is_external_other_other_other_tobacco: Optional[bool] = Field(None, description="Order is external other other other tobacco")
    order_is_external_other_other_other_hookah: Optional[bool] = Field(None, description="Order is external other other other hookah")
    order_is_external_other_other_other_other: Optional[bool] = Field(None, description="Order is external other other other other")
    order_is_external_other_other_other_delivery: Optional[bool] = Field(None, description="Order is external other other other delivery")
    order_is_external_other_other_other_pickup: Optional[bool] = Field(None, description="Order is external other other other pickup")
    order_is_external_other_other_other_table_service: Optional[bool] = Field(None, description="Order is external other other other table service")
    order_is_external_other_other_other_takeaway: Optional[bool] = Field(None, description="Order is external other other other takeaway")
    order_is_external_other_other_other_drive_through: Optional[bool] = Field(None, description="Order is external other other other drive through")
    order_is_external_other_other_other_room_service: Optional[bool] = Field(None, description="Order is external other other other room service")
    order_is_external_other_other_other_catering: Optional[bool] = Field(None, description="Order is external other other other catering")
    order_is_external_other_other_other_banquet: Optional[bool] = Field(None, description="Order is external other other other banquet")
    order_is_external_other_other_other_retail: Optional[bool] = Field(None, description="Order is external other other other retail")
    order_is_external_other_other_other_other_service: Optional[bool] = Field(None, description="Order is external other other other other service")
    order_is_external_other_other_other_other_goods: Optional[bool] = Field(None, description="Order is external other other other other goods")
    order_is_external_other_other_other_other_tobacco: Optional[bool] = Field(None, description="Order is external other other other other tobacco")
    order_is_external_other_other_other_other_hookah: Optional[bool] = Field(None, description="Order is external other other other other hookah")
    order_is_external_other_other_other_other_other: Optional[bool] = Field(None, description="Order is external other other other other other")
    order_is_external_other_other_other_other_delivery: Optional[bool] = Field(None, description="Order is external other other other other delivery")
    order_is_external_other_other_other_other_pickup: Optional[bool] = Field(None, description="Order is external other other other other pickup")
    order_is_external_other_other_other_other_table_service: Optional[bool] = Field(None, description="Order is external other other other other table service")
    order_is_external_other_other_other_other_takeaway: Optional[bool] = Field(None, description="Order is external other other other other takeaway")
    order_is_external_other_other_other_other_drive_through: Optional[bool] = Field(None, description="Order is external other other other other drive through")
    order_is_external_other_other_other_other_room_service: Optional[bool] = Field(None, description="Order is external other other other other room service")
    order_is_external_other_other_other_other_catering: Optional[bool] = Field(None, description="Order is external other other other other catering")
    order_is_external_other_other_other_other_banquet: Optional[bool] = Field(None, description="Order is external other other other other banquet")
    order_is_external_other_other_other_other_retail: Optional[bool] = Field(None, description="Order is external other other other other retail")


class OrderByIdRequest(BaseModel):
    """Request model for order by ID"""
    organization_ids: List[str] = Field(..., description="Organization IDs")
    order_ids: List[str] = Field(..., description="Order IDs")


class OrderByIdResponse(BaseModel):
    """Response model for order by ID"""
    orders: List[Order] = Field(..., description="Orders")
