"""
销项发票 Pydantic V2 Schemas
"""
from __future__ import annotations

import uuid
from datetime import date, datetime

from pydantic import BaseModel, Field


class SalesInvoiceCreate(BaseModel):
    issuer: str = Field(..., min_length=1, max_length=200, examples=["XX润滑油有限公司"])
    receiver_customer_id: uuid.UUID = Field(..., description="受票方客户 ID")
    invoice_number: str = Field(..., min_length=1, max_length=100, examples=["INV-20260312-001"])
    amount: float = Field(..., gt=0, description="票面金额")
    billing_date: date = Field(..., description="开票日期")
    remark: str | None = None


class SalesInvoiceUpdate(BaseModel):
    payment_status: str | None = Field(
        default=None, pattern=r"^(未回款|部分回款|已结清)$",
        description="回款状态",
    )
    payment_date: date | None = None
    payment_amount: float | None = Field(default=None, ge=0, description="已回款金额")
    remark: str | None = None


class SalesInvoiceResponse(BaseModel):
    id: uuid.UUID
    issuer: str
    receiver_customer_id: uuid.UUID
    customer_name: str | None = None
    invoice_number: str
    amount: float
    billing_date: date
    payment_status: str = "未回款"
    payment_date: date | None = None
    payment_amount: float = 0
    remark: str | None = None
    created_by: uuid.UUID | None = None
    creator_name: str | None = None
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


class SalesInvoiceListResponse(BaseModel):
    total: int
    items: list[SalesInvoiceResponse]
    page: int
    size: int
