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

class UnitConversionBase(BaseModel):
    # 👇 OJO: Son códigos (Strings), no IDs
    from_unit_code: str = Field(..., max_length=5, description="Source Unit Code")
    to_unit_code: str = Field(..., max_length=5, description="Target Unit Code")
    conversion_factor: Optional[Decimal] = Field(None, description="Conversion Factor")

class UnitConversionCreate(UnitConversionBase):
    pass

class UnitConversionUpdate(BaseModel):
    from_unit_code: Optional[str] = Field(None, max_length=5)
    to_unit_code: Optional[str] = Field(None, max_length=5)
    conversion_factor: Optional[Decimal] = None

class UnitConversionResponse(UnitConversionBase):
    id: int
    tenant_id: int 
    company_id: int  

    model_config = ConfigDict(from_attributes=True)