# -*- coding: utf-8 -*-
"""
客户主表模型
CRM 的核心实体，所有业务表 (日志/标签/待办/销售机会) 均通过外键关联到此表。
"""

import uuid
from datetime import datetime

from sqlalchemy import String, Text, func
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import Mapped, mapped_column

from app.core.database import Base


class Client(Base):
    """
    客户信息表 (clients)
    记录客户基本信息，作为 CRM 业务数据的核心关联实体。
    """

    __tablename__ = "clients"

    id: Mapped[uuid.UUID] = mapped_column(
        UUID(as_uuid=True), primary_key=True, default=uuid.uuid4,
    )
    name: Mapped[str] = mapped_column(
        String(200), nullable=False, index=True,
        comment="客户名称 (公司名/个人名)",
    )
    contact_person: Mapped[str | None] = mapped_column(
        String(100), nullable=True,
        comment="联系人姓名",
    )
    phone: Mapped[str | None] = mapped_column(
        String(30), nullable=True,
        comment="联系电话",
    )
    address: Mapped[str | None] = mapped_column(
        String(500), nullable=True,
        comment="地址",
    )
    notes: Mapped[str | None] = mapped_column(
        Text, nullable=True,
        comment="备注",
    )
    created_at: Mapped[datetime] = mapped_column(
        server_default=func.now(),
    )
    updated_at: Mapped[datetime] = mapped_column(
        server_default=func.now(),
        onupdate=func.now(),
    )
