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

class IdentifierBase(BaseModel):
    code: str = Field(..., max_length=2, description="Identifier Code (CLAVE)")
    description: Optional[str] = Field(
        None, max_length=1000, description="Description")
    level: Optional[str] = Field(None, max_length=1, description="Level")
    complement: Optional[str] = Field(
        None, max_length=5000, description="Complement")

class IdentifierCreate(IdentifierBase):
    pass

class IdentifierUpdate(BaseModel):
    code: Optional[str] = Field(None, max_length=2)
    description: Optional[str] = Field(None, max_length=1000)
    level: Optional[str] = Field(None, max_length=1)
    complement: Optional[str] = Field(None, max_length=5000)

class IdentifierResponse(IdentifierBase):
    id: int
    tenant_id: int
    company_id: int 

    model_config = ConfigDict(from_attributes=True)


class IdentifierDetailBase(BaseModel):
    invoice_consecutive: Optional[int] = Field(
        None, description="Invoice Consecutive")
    part_line: Optional[int] = Field(None, description="Part Line")
    identifier_code: Optional[str] = Field(
        None, max_length=2, description="Identifier Code")
    item_line_id: Optional[int] = Field(None, description="Item Line ID")
    module: Optional[str] = Field(None, max_length=20, description="Module")
    complement1: Optional[str] = Field(
        None, max_length=50, description="Complement 1")
    complement2: Optional[str] = Field(
        None, max_length=51, description="Complement 2")
    complement3: Optional[str] = Field(
        None, max_length=50, description="Complement 3")

class IdentifierDetailCreate(IdentifierDetailBase):
    pass

class IdentifierDetailUpdate(BaseModel):
    invoice_consecutive: Optional[int] = None
    part_line: Optional[int] = None
    identifier_code: Optional[str] = Field(None, max_length=2)
    module: Optional[str] = Field(None, max_length=20)
    complement1: Optional[str] = Field(None, max_length=50)
    complement2: Optional[str] = Field(None, max_length=51)
    complement3: Optional[str] = Field(None, max_length=50)

class IdentifierDetailResponse(IdentifierDetailBase):
    id: int
    tenant_id: int
    company_id: int

    model_config = ConfigDict(from_attributes=True)