# app/schemas.py from pydantic import BaseModel, Field from typing import List, Optional # --- Classification Result Model --- class ClassificationResult(BaseModel): """Defines the structured output for the classification agent.""" category: str = Field(description="The category of the document, must be one of ['LETTER', 'INVOICE', 'RECEIPT', 'CONTRACT', 'OTHER']") language: str = Field(description="The detected primary language of the document as a two-letter code (e.g., 'en', 'zh', 'es').") # --- Existing Model (Unchanged) --- class ReceiptItem(BaseModel): name: str = Field(description="The name of the purchased item or service") quantity: float = Field(description="The quantity of the item") price: float = Field(description="The unit price of the item") class ReceiptInfo(BaseModel): merchant_name: Optional[str] = Field(None, description="The name of the merchant or store") transaction_date: Optional[str] = Field(None, description="The transaction date in the YYYY-MM-DD format") total_amount: Optional[float] = Field(None, description="The total amount on the receipt") items: Optional[List[ReceiptItem]] = Field(None, description="The list of all purchased items") # --- Added: Invoice Line Item Model --- class LineItem(BaseModel): """Defines a single line item from an invoice.""" description: Optional[str] = Field("", description="The description of the product or service.") quantity: Optional[float] = Field(None, description="The quantity of the item.") unit_price: Optional[float] = Field(None, description="The price for a single unit of the item.") total_price: Optional[float] = Field(None, description="The total price for this line item (quantity * unit_price).") class InvoiceInfo(BaseModel): """Defines the detailed, structured information to be extracted from an invoice.""" date: Optional[str] = Field("", description="Extract in YYYY-MM-DD format. If unclear, leave as an empty string.") invoice_number: Optional[str] = Field("", description="If not found or unclear, leave as an empty string.") supplier_number: Optional[str] = Field("", description="It's the organisation number. If not found or unclear, leave as an empty string.") biller_name: Optional[str] = Field("", description="It's the sender's name. If not found or unclear, leave as an empty string.") amount: Optional[float] = Field(None, description="Extract and format to decimal. If not present, leave as null.") customer_name: Optional[str] = Field("", description="It's the receiver's name. Clean any special chars from the name. If not found or unclear, leave as an empty string.") customer_address: Optional[str] = Field("", description="It's the receiver's address. Put it in one line. If not found or unclear, leave as an empty string.") customer_address_line: Optional[str] = Field("", description="It's the receiver's address line, not the whole address. If not found or unclear, leave as an empty string.") customer_address_city: Optional[str] = Field("", description="It's the receiver's address city. If not found, find a city in the document. If unclear, leave as an empty string.") customer_address_country: Optional[str] = Field("", description="It's the receiver's address country. If not found, find the country of the extracted city. If unclear, leave as an empty string.") customer_address_postal_code: Optional[str] = Field("", description="It's the receiver's address postal code. If not found or unclear, leave as an empty string.") customer_address_apartment: Optional[str] = Field("", description="It's the receiver's address apartment or suite. If not found or unclear, leave as an empty string.") customer_address_region: Optional[str] = Field("", description="It's the receiver's address region. If not found, find the region of the extracted city or country. If unclear, leave as an empty string.") customer_address_care_of: Optional[str] = Field("", description="It's the receiver's address care of. If not found or unclear, leave as an empty string.") billo_id: Optional[str] = Field("", description="Extract from customer_address if it exists, following the format 'LLL NNN-A'. If not found or unclear, leave as an empty string.") bank_giro: Optional[str] = Field("", description="BankGiro number, e.g., '123-4567'. If not found, leave as an empty string.") plus_giro: Optional[str] = Field("", description="PlusGiro number, e.g., '123456-7'. If not found, leave as an empty string.") customer_ssn: Optional[str] = Field("", description="Customer's social security number, e.g., 'YYYYMMDD-XXXX'. If not found, leave as an empty string.") line_items: List[LineItem] = Field([], description="A list of all line items from the invoice.")