from sqlalchemy import String, Enum
from sqlalchemy.orm import Mapped, mapped_column
from .base import BaseModel

class Status(BaseModel):
    """
    Dynamic Status Management.
    """
    __tablename__ = 'status'

    module: Mapped[str] = mapped_column(String(50), nullable=False) # crm, erp, hris
    sub_module: Mapped[str | None] = mapped_column(String(50), nullable=True) # leads, tickets, projects, invoices, attendance, etc.
    name: Mapped[str] = mapped_column(String(50), nullable=False)
    slug: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
    color: Mapped[str] = mapped_column(String(20), default='secondary') # Bootstrap color class or hex

    # System Tag for Business Logic
    # NEW: Initial state
    # PROCESS: Work in progress
    # FINAL_CONVERTIBLE: Success state (can convert to next stage)
    # FINAL_CLOSED: Dead/Lost/Done state
    system_tag: Mapped[str] = mapped_column(String(50), nullable=False)

    def __repr__(self):
        return f"<Status {self.name} ({self.system_tag})>"
