"""Experience 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 ProviderKind(str, enum.Enum):
    THEME_MARKETPLACE = "theme_marketplace"
    COMPONENT_MARKETPLACE = "component_marketplace"
    CDN = "cdn"
    STORAGE = "storage"
    RENDER = "render"
    CUSTOM = "custom"


class ProviderStatus(str, enum.Enum):
    REGISTERED = "registered"
    ACTIVE = "active"
    INACTIVE = "inactive"
    FAILED = "failed"
    RETIRED = "retired"


class RenderEngineStatus(str, enum.Enum):
    REGISTERED = "registered"
    READY = "ready"
    ACTIVE = "active"
    DISABLED = "disabled"


class AuditAction(str, enum.Enum):
    CREATE = "create"
    UPDATE = "update"
    DELETE = "delete"
    RESTORE = "restore"
    STATUS_CHANGE = "status_change"
    REGISTER = "register"
    ENABLE = "enable"
    DISABLE = "disable"
    PUBLISH = "publish"
    UNPUBLISH = "unpublish"
    ARCHIVE = "archive"
    ACTIVATE = "activate"
    DEPRECATE = "deprecate"
    ASSIGN = "assign"
    REPLACE = "replace"


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


class PageType(str, enum.Enum):
    LANDING = "landing"
    MINI_SITE = "mini_site"
    BUSINESS_WEBSITE = "business_website"
    PORTFOLIO = "portfolio"
    RESTAURANT = "restaurant"
    CAFE = "cafe"
    COMPANY = "company"
    BUSINESS_PROFILE = "business_profile"
    DIGITAL_MENU = "digital_menu"
    DIGITAL_CATALOG = "digital_catalog"
    PRODUCT_CATALOG = "product_catalog"
    QR = "qr"
    LINK_IN_BIO = "link_in_bio"
    APPOINTMENT = "appointment"
    FORM = "form"
    BLOG = "blog"
    CAMPAIGN = "campaign"
    KNOWLEDGE = "knowledge"
    DOCUMENTATION = "documentation"
    MEDIA = "media"
    SEO = "seo"
    PUBLIC_PROFILE = "public_profile"
    EVENT = "event"
    CUSTOM = "custom"


class DomainKind(str, enum.Enum):
    SUBDOMAIN = "subdomain"
    CUSTOM = "custom"
    PATH = "path"


class ComponentKind(str, enum.Enum):
    LAYOUT_BLOCK = "layout_block"
    CONTENT = "content"
    MEDIA = "media"
    NAVIGATION = "navigation"
    FORM_SHELL = "form_shell"
    WIDGET_SHELL = "widget_shell"
    CTA = "cta"
    HERO = "hero"
    MENU_REF = "menu_ref"
    CATALOG_REF = "catalog_ref"
    CUSTOM = "custom"


class ComponentStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    DEPRECATED = "deprecated"
    ARCHIVED = "archived"


class ComponentVersionStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    RETIRED = "retired"


class ThemeStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    DEPRECATED = "deprecated"
    ARCHIVED = "archived"


class LayoutStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    DEPRECATED = "deprecated"
    ARCHIVED = "archived"


class DirectionMode(str, enum.Enum):
    RTL = "rtl"
    LTR = "ltr"
    BOTH = "both"


class ThemeVersionStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    RETIRED = "retired"


class LayoutVersionStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    RETIRED = "retired"


class LayoutKind(str, enum.Enum):
    PAGE_SHELL = "page_shell"
    APP_SHELL = "app_shell"
    SIDEBAR = "sidebar"
    SPLIT = "split"
    CUSTOM = "custom"


class TemplateStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    DEPRECATED = "deprecated"
    ARCHIVED = "archived"


class TemplateVersionStatus(str, enum.Enum):
    DRAFT = "draft"
    PUBLISHED = "published"
    RETIRED = "retired"


class TemplateInstantiationStatus(str, enum.Enum):
    PENDING = "pending"
    COMPLETED = "completed"
    FAILED = "failed"


# Phase 11.5 — Localization, RTL/LTR & Media
class TextDirection(str, enum.Enum):
    RTL = "rtl"
    LTR = "ltr"


class LocalizationTarget(str, enum.Enum):
    SITE = "site"
    PAGE = "page"
    COMPONENT_PLACEMENT = "component_placement"
    TEMPLATE = "template"
    THEME = "theme"
    LAYOUT = "layout"
    MEDIA_REF = "media_ref"


class LocalizationStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class MediaKind(str, enum.Enum):
    IMAGE = "image"
    VIDEO = "video"
    DOCUMENT = "document"
    AUDIO = "audio"
    ICON = "icon"
    OTHER = "other"


class MediaRefStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


# Phase 11.6 — Forms, Surveys & Appointments
class FormStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class FormSubmissionStatus(str, enum.Enum):
    RECEIVED = "received"
    PROCESSED = "processed"
    FAILED = "failed"
    ARCHIVED = "archived"


class SurveyStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class SurveyResponseStatus(str, enum.Enum):
    RECEIVED = "received"
    PROCESSED = "processed"
    FAILED = "failed"
    ARCHIVED = "archived"


class AppointmentPageStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class AppointmentBookingStatus(str, enum.Enum):
    PENDING = "pending"
    CONFIRMED = "confirmed"
    CANCELLED = "cancelled"
    ARCHIVED = "archived"


# Phase 11.7 — Publishing, Domains, SEO & PWA
class PublishTarget(str, enum.Enum):
    SITE = "site"
    PAGE = "page"


class PublishReleaseStatus(str, enum.Enum):
    PENDING = "pending"
    PUBLISHED = "published"
    FAILED = "failed"
    ROLLED_BACK = "rolled_back"


class DomainEdgeStatus(str, enum.Enum):
    PENDING = "pending"
    PROVISIONING = "provisioning"
    READY = "ready"
    FAILED = "failed"
    RETIRED = "retired"


class SeoTarget(str, enum.Enum):
    SITE = "site"
    PAGE = "page"


class SeoStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class SitemapStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class RobotsStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class PwaStatus(str, enum.Enum):
    DRAFT = "draft"
    READY = "ready"
    ARCHIVED = "archived"


# Phase 11.8 — Bundles, Licensing & Feature Toggles
class BundleKey(str, enum.Enum):
    MINI_SITE = "mini_site"
    BUSINESS_WEBSITE = "business_website"
    LANDING_BUILDER = "landing_builder"
    DIGITAL_MENU = "digital_menu"
    DIGITAL_CATALOG = "digital_catalog"
    PORTFOLIO = "portfolio"
    BLOG = "blog"
    APPOINTMENT = "appointment"
    CAMPAIGN = "campaign"
    QR_LANDING = "qr_landing"
    BIO_LINK = "bio_link"
    CUSTOM_DOMAIN = "custom_domain"
    SEO = "seo"
    ANALYTICS = "analytics"
    AI_CONTENT = "ai_content"
    FORMS = "forms"
    WIDGETS = "widgets"
    CUSTOM = "custom"


class BundleDefinitionStatus(str, enum.Enum):
    DRAFT = "draft"
    AVAILABLE = "available"
    RETIRED = "retired"


class TenantBundleStatus(str, enum.Enum):
    PENDING = "pending"
    ACTIVE = "active"
    SUSPENDED = "suspended"
    EXPIRED = "expired"
    REVOKED = "revoked"


class LicenseBindingStatus(str, enum.Enum):
    PENDING = "pending"
    ACTIVE = "active"
    EXPIRED = "expired"
    REVOKED = "revoked"


class FeatureToggleStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


# Phase 11.9 — Consumer Integrations & Widgets
class ConsumerConnectorKind(str, enum.Enum):
    HOSPITALITY = "hospitality"
    MARKETPLACE = "marketplace"
    SPORTS_CENTER = "sports_center"
    CRM = "crm"
    ACCOUNTING = "accounting"
    LOYALTY = "loyalty"
    COMMUNICATION = "communication"
    DELIVERY = "delivery"
    AUTOMATION = "automation"
    ACADEMY = "academy"
    CLINIC = "clinic"
    HOTEL = "hotel"
    TOURISM = "tourism"
    CUSTOM = "custom"


class ConsumerConnectorStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    SUSPENDED = "suspended"
    RETIRED = "retired"


class ConnectorDispatchDirection(str, enum.Enum):
    OUTBOUND = "outbound"
    INBOUND = "inbound"


class ConnectorDispatchStatus(str, enum.Enum):
    PENDING = "pending"
    ACKNOWLEDGED = "acknowledged"
    FAILED = "failed"
    CANCELLED = "cancelled"


class WidgetKind(str, enum.Enum):
    MENU_EMBED = "menu_embed"
    CATALOG_EMBED = "catalog_embed"
    BOOKING_EMBED = "booking_embed"
    FORM_EMBED = "form_embed"
    LOYALTY_EMBED = "loyalty_embed"
    CRM_LEAD_CAPTURE = "crm_lead_capture"
    CUSTOM = "custom"


class WidgetDefinitionStatus(str, enum.Enum):
    DRAFT = "draft"
    AVAILABLE = "available"
    RETIRED = "retired"


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


class NotifyDispatchStatus(str, enum.Enum):
    PENDING = "pending"
    SENT = "sent"
    FAILED = "failed"
    CANCELLED = "cancelled"


# Phase 11.10 — Analytics & AI Content Hooks
class AnalyticsReportStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    ARCHIVED = "archived"


class AnalyticsSnapshotStatus(str, enum.Enum):
    ACTIVE = "active"
    ARCHIVED = "archived"


class AiContentTaskKind(str, enum.Enum):
    PAGE_COPY = "page_copy"
    SEO_META = "seo_meta"
    COMPONENT_TEXT = "component_text"
    FORM_COPY = "form_copy"
    CAMPAIGN_COPY = "campaign_copy"
    CUSTOM = "custom"


class AiContentHookStatus(str, enum.Enum):
    DRAFT = "draft"
    ACTIVE = "active"
    SUSPENDED = "suspended"
    RETIRED = "retired"


class AiContentDispatchStatus(str, enum.Enum):
    PENDING = "pending"
    GENERATED = "generated"
    FAILED = "failed"
    CANCELLED = "cancelled"
