"""Hospitality domain enums and dialect-safe GUID type."""
from __future__ import annotations

import enum
import uuid

from sqlalchemy.dialects.postgresql import UUID as PG_UUID
from sqlalchemy.types import CHAR, TypeDecorator


class GUID(TypeDecorator):
    impl = CHAR
    cache_ok = True

    def load_dialect_impl(self, dialect):
        if dialect.name == "postgresql":
            return dialect.type_descriptor(PG_UUID(as_uuid=True))
        return dialect.type_descriptor(CHAR(36))

    def process_bind_param(self, value, dialect):
        if value is None:
            return value
        if dialect.name == "postgresql":
            return value if isinstance(value, uuid.UUID) else uuid.UUID(str(value))
        return str(value)

    def process_result_value(self, value, dialect):
        if value is None:
            return value
        if isinstance(value, uuid.UUID):
            return value
        return uuid.UUID(str(value))


class LifecycleStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    INACTIVE = "inactive"
    SUSPENDED = "suspended"
    ARCHIVED = "archived"


class VenueFormat(str, enum.Enum):
    """Configurable venue formats — never hardcoded business engines."""

    CAFE = "cafe"
    COFFEE_SHOP = "coffee_shop"
    RESTAURANT = "restaurant"
    FAST_FOOD = "fast_food"
    BAKERY = "bakery"
    PASTRY = "pastry"
    ICE_CREAM = "ice_cream"
    JUICE_BAR = "juice_bar"
    CLOUD_KITCHEN = "cloud_kitchen"
    FOOD_COURT = "food_court"
    CATERING = "catering"
    TAKE_AWAY = "take_away"
    OTHER = "other"


class BundleKey(str, enum.Enum):
    """Licensable feature bundles — activation is tenant-scoped."""

    DIGITAL_MENU = "digital_menu"
    QR_MENU = "qr_menu"
    QR_ORDERING = "qr_ordering"
    POS_LITE = "pos_lite"
    POS_PRO = "pos_pro"
    KITCHEN = "kitchen"
    RESERVATION = "reservation"
    TABLE_SERVICE = "table_service"
    DELIVERY_CONNECTOR = "delivery_connector"
    ACCOUNTING_CONNECTOR = "accounting_connector"
    CRM_CONNECTOR = "crm_connector"
    LOYALTY_CONNECTOR = "loyalty_connector"
    COMMUNICATION_CONNECTOR = "communication_connector"
    WEBSITE_CONNECTOR = "website_connector"
    ANALYTICS = "analytics"
    AI_ASSISTANT = "ai_assistant"


class BundleStatus(str, enum.Enum):
    AVAILABLE = "available"
    ACTIVE = "active"
    SUSPENDED = "suspended"
    RETIRED = "retired"


class TableStatus(str, enum.Enum):
    AVAILABLE = "available"
    OCCUPIED = "occupied"
    RESERVED = "reserved"
    CLEANING = "cleaning"
    OUT_OF_SERVICE = "out_of_service"


class MenuStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    ARCHIVED = "archived"


class AuditAction(str, enum.Enum):
    CREATE = "create"
    UPDATE = "update"
    DELETE = "delete"
    RESTORE = "restore"
    STATUS_CHANGE = "status_change"
    ACTIVATE = "activate"
    DEACTIVATE = "deactivate"
