from decimal import Decimal
from typing import Optional
from pydantic import BaseModel, Field, ConfigDict

# ============================================================================
# LINE QUANTITY SCHEMAS
# ============================================================================

class LineQuantityBase(BaseModel):
    """Base schema for line quantities"""
    # Quantities
    quantity: Optional[Decimal] = Field(None, description="Main quantity (CANTIMPO/CANTEXPO/CANTIMPODEF)")
    alternate_quantity: Optional[Decimal] = Field(None, description="Alternate quantity (CANTALTERNA)")
    quantity_uma: Optional[Decimal] = Field(None, description="UMA quantity (CANTIMPOUMA/CANTEXPOUMA)")
    auxiliary_quantity: Optional[Decimal] = Field(None, description="Auxiliary quantity (CANTIMPOAUXILIAR/CANTEXPOAUXILIAR)")
    
    # Quantities - Special (SCAF specific)
    quantity_temp_export: Optional[Decimal] = Field(None, description="Temporary export quantity (CANTEXPOTEMP)")
    serial_count: Optional[int] = Field(None, description="Serial count (CANT_SERIES/CANT_SERIESDEF)")
    
    # Weight
    net_weight: Optional[Decimal] = Field(None, description="Net weight (PESONETO)")
    gross_weight: Optional[Decimal] = Field(None, description="Gross weight (PESOBRUTO)")
    
    # Packaging
    package_id: Optional[int] = Field(None, description="Package ID (GBultos)")
    package_quantity: Optional[int] = Field(None, description="Package quantity (CANTBULTOS)")
    container_quantity: Optional[int] = Field(None, description="Container quantity (CANTBULCONT)")
    container_description: Optional[str] = Field(None, max_length=40, description="Container description (DESCCONTENEDOR)")
    box_count: Optional[str] = Field(None, max_length=30, description="Box count (NOCAJAS)")


class LineQuantityCreate(LineQuantityBase):
    """Schema for creating line quantity"""
    pass


class LineQuantityUpdate(LineQuantityBase):
    """Schema for updating line quantity"""
    pass


class LineQuantityResponse(LineQuantityBase):
    """Schema for line quantity response"""
    id: int
    item_line_id: int

    model_config = ConfigDict(from_attributes=True)