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

# ============================================================================
# LINE DESCRIPTION SCHEMAS
# ============================================================================

class LineDescriptionBase(BaseModel):
    """Base schema for line descriptions"""
    # Descriptions
    description_spanish: Optional[str] = Field(None, max_length=4999, description="Description in Spanish (DESCRIPCIONE)")
    description_english: Optional[str] = Field(None, max_length=4999, description="Description in English (DESCRIPCIONI)")
    extra_description: Optional[str] = Field(None, description="Extra description (DESCRIPCIONEEXTRA)")
    part_description: Optional[str] = Field(None, max_length=500, description="Part description (DESCRIPCIONPARTE)")
    class_description: Optional[str] = Field(None, max_length=500, description="Class description (DESCRIPCIONCLASE)")
    package_description: Optional[str] = Field(None, max_length=500, description="Package description (DESCRIPCIONBULTO)")
    
    # Product attributes
    brand: Optional[str] = Field(None, max_length=50, description="Brand (MARCA)")
    model: Optional[str] = Field(None, max_length=50, description="Model (MODELO)")
    has_serial: Optional[bool] = Field(None, description="Has serial (LLEVASERIE)")
    
    # Additional information
    additional_info_spanish: Optional[str] = Field(None, max_length=1000, description="Additional info in Spanish (INFOADICIONESP)")
    additional_info_english: Optional[str] = Field(None, max_length=1000, description="Additional info in English (INFOADICIONING)")
    
    # Lot and entry tracking
    lot: Optional[str] = Field(None, max_length=254, description="Lot (LOTE)")
    entry_number: Optional[str] = Field(None, max_length=50, description="Entry number (NUMENTRADA/NUMERODEENTRADA)")
    
    # Eighth rule and A31 fields
    eighth_rule_fraction: Optional[str] = Field(None, max_length=20, description="Eighth Rule Fraction")
    eighth_rule_line: Optional[int] = Field(None, description="Eighth Rule Line")
    consider_a31: Optional[bool] = Field(False, description="Consider in A31")
    
    # Machinery location
    machinery_location: Optional[str] = Field(None, max_length=200, description="Machinery and equipment location")


class LineDescriptionCreate(LineDescriptionBase):
    """Schema for creating line description"""
    pass


class LineDescriptionUpdate(LineDescriptionBase):
    """Schema for updating line description"""
    pass


class LineDescriptionResponse(LineDescriptionBase):
    """Schema for line description response"""
    id: int
    item_line_id: int

    model_config = ConfigDict(from_attributes=True)
