from datetime import date as Date
from datetime import datetime
from datetime import time as Time
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class PedimentoPaymentsBase(BaseModel):
    """Base schema for Pedimento Payments"""

    pedimento_id: Optional[int] = Field(None, description="Pedimento ID")
    tenant_id: Optional[int] = Field(None, description="Tenant ID")
    acknowledgment: Optional[str] = Field(
        None, max_length=20, description="Acknowledgment"
    )
    operation_number: Optional[str] = Field(
        None, max_length=14, description="Operation number"
    )
    bank_code: Optional[int] = Field(None, description="Bank code")
    cashier: Optional[str] = Field(None, max_length=2, description="Cashier")
    date: Optional[Date] = Field(None, description="Date")
    time: Optional[Time] = Field(None, description="Time")
    shift: Optional[str] = Field(None, max_length=1, description="Shift")
    total_cash_paid: Optional[int] = Field(None, description="Total cash paid")
    total_contributions: Optional[int] = Field(None, description="Total contributions")
    counter_payment: Optional[int] = Field(None, description="Counter payment")
    pece_code: Optional[str] = Field(None, max_length=5, description="PECE code")    


class PedimentoPaymentsCreate(BaseModel):
    """Schema for creating a new Pedimento Payments - pedimento_id and tenant_id are set by backend"""

    acknowledgment: Optional[str] = Field(None, max_length=20, description="Acknowledgment")
    operation_number: Optional[str] = Field(None, max_length=14, description="Operation number")
    bank_code: Optional[int] = Field(None, description="Bank code")
    cashier: Optional[str] = Field(None, max_length=2, description="Cashier")
    date: Optional[Date] = Field(None, description="Date")
    time: Optional[Time] = Field(None, description="Time")
    shift: Optional[str] = Field(None, max_length=1, description="Shift")
    total_cash_paid: Optional[int] = Field(None, description="Total cash paid")
    total_contributions: Optional[int] = Field(None, description="Total contributions")
    counter_payment: Optional[int] = Field(None, description="Counter payment")
    pece_code: Optional[str] = Field(None, max_length=5, description="PECE code")    


class PedimentoPaymentsUpdate(BaseModel):
    """Schema for updating a Pedimento Payments"""

    acknowledgment: Optional[str] = Field(None, max_length=20)
    operation_number: Optional[str] = Field(None, max_length=14)
    bank_code: Optional[int] = None
    cashier: Optional[str] = Field(None, max_length=2)
    date: Optional[Date] = None
    time: Optional[Time] = None
    shift: Optional[str] = Field(None, max_length=1)
    total_cash_paid: Optional[int] = None
    total_contributions: Optional[int] = None
    counter_payment: Optional[int] = None
    pece_code: Optional[str] = Field(None, max_length=5)    


class PedimentoPaymentsResponse(PedimentoPaymentsBase):
    """Schema for Pedimento Payments response"""

    id: int
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)
