"""
CRM 客户域 Pydantic V2 Schemas
"""

from __future__ import annotations

import uuid
from datetime import datetime

from typing import Any

from pydantic import BaseModel, Field


# ── 创建 ──────────────────────────────────────────────────
class CustomerCreate(BaseModel):
    name: str = Field(..., min_length=1, max_length=200, examples=["中石化润滑油公司"])
    level: str = Field(default="C", pattern=r"^[ABC]$")
    industry: str | None = Field(default=None, max_length=100)
    contact: str | None = Field(default=None, max_length=50)
    phone: str | None = Field(default=None, max_length=30)
    email: str | None = Field(default=None, max_length=100)
    address: str | None = None
    status: int = Field(default=1, ge=0, le=1)


# ── 更新 ──────────────────────────────────────────────────
class CustomerUpdate(BaseModel):
    name: str | None = Field(default=None, min_length=1, max_length=200)
    level: str | None = Field(default=None, pattern=r"^[ABC]$")
    industry: str | None = Field(default=None, max_length=100)
    contact: str | None = Field(default=None, max_length=50)
    phone: str | None = Field(default=None, max_length=30)
    email: str | None = Field(default=None, max_length=100)
    address: str | None = None
    status: int | None = Field(default=None, ge=0, le=1)


# ── 响应 ──────────────────────────────────────────────────
class CustomerResponse(BaseModel):
    id: uuid.UUID
    name: str
    level: str
    industry: str | None = None
    contact: str | None = None
    phone: str | None = None
    email: str | None = None
    address: str | None = None
    ai_score: float = 0
    ai_persona: dict[str, Any] | None = None
    owner_id: uuid.UUID | None = None
    owner_name: str | None = None
    status: int = 1
    is_deleted: bool = False
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


# ── 分页列表 ─────────────────────────────────────────────
class CustomerListResponse(BaseModel):
    total: int
    items: list[CustomerResponse]
    page: int
    size: int
