from datetime import datetime, time
from typing import Optional

from pydantic import BaseModel, ConfigDict, Field


class PedimentoDatesBase(BaseModel):
    """Base schema for Pedimento Dates"""

    entry_date: datetime = Field(..., description="Entry date")
    pedimento_date: Optional[datetime] = Field(None, description="Pedimento date")    
    payment_date: Optional[datetime] = Field(None, description="Payment date")
    rectification_payment_date: Optional[datetime] = Field(
        None, description="Rectification payment date"
    )
    extraction_date: Optional[datetime] = Field(None, description="Extraction date")
    submission_date: Optional[datetime] = Field(None, description="Submission date")
    eucan_date: Optional[datetime] = Field(None, description="EUCAN date")
    original_date: Optional[datetime] = Field(None, description="Original date")
    start_date: Optional[datetime] = Field(None, description="Start date")
    end_date: datetime = Field(..., description="End date")


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

    entry_date: datetime = Field(..., description="Entry date")
    pedimento_date: Optional[datetime] = Field(None, description="Pedimento date")    
    payment_date: Optional[datetime] = Field(None, description="Payment date")
    rectification_payment_date: Optional[datetime] = Field(None, description="Rectification payment date")
    extraction_date: Optional[datetime] = Field(None, description="Extraction date")
    submission_date: Optional[datetime] = Field(None, description="Submission date")
    eucan_date: Optional[datetime] = Field(None, description="EUCAN date")
    original_date: Optional[datetime] = Field(None, description="Original date")
    start_date: Optional[datetime] = Field(None, description="Start date")
    end_date: datetime = Field(..., description="End date")    


class PedimentoDatesUpdate(BaseModel):
    """Schema for updating a Pedimento Dates"""

    entry_date: Optional[datetime] = None
    pedimento_date: Optional[datetime] = None    
    payment_date: Optional[datetime] = None
    rectification_payment_date: Optional[datetime] = None
    extraction_date: Optional[datetime] = None
    submission_date: Optional[datetime] = None
    eucan_date: Optional[datetime] = None
    original_date: Optional[datetime] = None
    start_date: Optional[datetime] = None
    end_date: Optional[datetime] = None


class PedimentoDatesResponse(PedimentoDatesBase):
    """Schema for Pedimento Dates response"""

    id: int
    pedimento_id: int = Field(..., description="Pedimento ID")
    tenant_id: int = Field(..., description="Tenant ID")
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)
