from __future__ import annotations

from dataclasses import asdict, dataclass, field
from typing import Any


BUILTIN_CUSTOMER_FIELDS = {
    "name",
    "primary_phone",
    "birthday",
    "tags",
    "notes",
}


@dataclass(slots=True)
class FieldDefinition:
    field_key: str
    label: str
    value_type: str = "string"
    entity_type: str = "customer"
    is_required: bool = False
    source: str = "user_confirmed"
    status: str = "active"
    aliases: list[str] = field(default_factory=list)

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


@dataclass(slots=True)
class CustomerPayload:
    name: str
    primary_phone: str | None = None
    birthday: str | None = None
    tags: list[str] = field(default_factory=list)
    notes: str | None = None
    dynamic_fields: dict[str, Any] = field(default_factory=dict)

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


@dataclass(slots=True)
class BusinessRecordPayload:
    customer_id: str
    record_type: str
    status: str | None = None
    record_date: str | None = None
    amount: str | None = None
    title: str | None = None
    raw_payload: dict[str, Any] = field(default_factory=dict)

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


@dataclass(slots=True)
class ReminderPlan:
    customer_id: str
    customer_name: str
    reminder_type: str
    title: str
    trigger_at: str | None
    cron_expr: str
    message: str
    recurring: bool = False

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


@dataclass(slots=True)
class ImportPreview:
    mode: str
    source_file: str
    customer_count: int
    record_count: int
    new_field_count: int
    warnings: list[str] = field(default_factory=list)
    preview_rows: list[dict[str, Any]] = field(default_factory=list)

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)
