"""
Pydantic schemas for invoice-related requests and responses.
"""
from pydantic import BaseModel, Field
from typing import Optional


class CreateInvoiceRequest(BaseModel):
    """Schema for creating an invoice."""
    booking_id: int = Field(..., gt=0, description="Booking ID")
    tax_rate: float = Field(0.0, ge=0, le=100, description="Tax rate percentage")
    discount_amount: float = Field(0.0, ge=0, description="Discount amount")
    due_days: int = Field(30, ge=1, le=365, description="Number of days until due")
    company_name: Optional[str] = Field(None, max_length=200)
    company_address: Optional[str] = Field(None, max_length=500)
    company_phone: Optional[str] = Field(None, max_length=50)
    company_email: Optional[str] = Field(None, max_length=255)
    company_tax_id: Optional[str] = Field(None, max_length=50)
    company_logo_url: Optional[str] = Field(None, max_length=500)
    customer_tax_id: Optional[str] = Field(None, max_length=50)
    notes: Optional[str] = Field(None, max_length=1000)
    terms_and_conditions: Optional[str] = None
    payment_instructions: Optional[str] = None
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "booking_id": 1,
                "tax_rate": 10.0,
                "discount_amount": 0.0,
                "due_days": 30,
                "company_name": "Hotel Name",
                "company_address": "123 Main St",
                "notes": "Payment due within 30 days"
            }
        }
    }


class UpdateInvoiceRequest(BaseModel):
    """Schema for updating an invoice."""
    company_name: Optional[str] = Field(None, max_length=200)
    company_address: Optional[str] = Field(None, max_length=500)
    company_phone: Optional[str] = Field(None, max_length=50)
    company_email: Optional[str] = Field(None, max_length=255)
    company_tax_id: Optional[str] = Field(None, max_length=50)
    company_logo_url: Optional[str] = Field(None, max_length=500)
    customer_tax_id: Optional[str] = Field(None, max_length=50)
    notes: Optional[str] = Field(None, max_length=1000)
    terms_and_conditions: Optional[str] = None
    payment_instructions: Optional[str] = None
    tax_rate: Optional[float] = Field(None, ge=0, le=100)
    discount_amount: Optional[float] = Field(None, ge=0)
    status: Optional[str] = None
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "notes": "Updated notes",
                "status": "paid"
            }
        }
    }


class MarkInvoicePaidRequest(BaseModel):
    """Schema for marking an invoice as paid."""
    amount: Optional[float] = Field(None, gt=0, description="Payment amount (optional, defaults to full amount)")
    
    model_config = {
        "json_schema_extra": {
            "example": {
                "amount": 500.00
            }
        }
    }

