from __future__ import annotations

import enum

from sqlalchemy import Enum, String, Text
from sqlalchemy.orm import Mapped, mapped_column, relationship

from app.db.base import Base, TimestampMixin, UUIDMixin


class CustomerType(str, enum.Enum):
    practice = "practice"
    clinic = "clinic"


class Customer(Base, UUIDMixin, TimestampMixin):
    __tablename__ = "customers"

    customer_type: Mapped[CustomerType] = mapped_column(Enum(CustomerType))
    name: Mapped[str] = mapped_column(String(220), index=True)
    street: Mapped[str | None] = mapped_column(String(220))
    postal_code: Mapped[str | None] = mapped_column(String(20))
    city: Mapped[str | None] = mapped_column(String(120))
    phone: Mapped[str | None] = mapped_column(String(80))
    email: Mapped[str | None] = mapped_column(String(255))
    hygiene_officer: Mapped[str | None] = mapped_column(String(160))
    quality_manager: Mapped[str | None] = mapped_column(String(160))
    notes: Mapped[str | None] = mapped_column(Text)

    contacts: Mapped[list["Contact"]] = relationship(back_populates="customer", cascade="all, delete-orphan")
    locations: Mapped[list["Location"]] = relationship(back_populates="customer", cascade="all, delete-orphan")

