"""
Core System Rich Choice Objects

This module defines all choice objects for core system functionality,
including health checks, API statuses, severity levels, alert types,
and other system-level choices.
"""

from .base import ChoiceCategory, RichChoice
from .registry import register_choices

# Health Check Status Choices
HEALTH_STATUSES = [
    RichChoice(
        value="healthy",
        label="Healthy",
        description="System is operating normally with no issues detected",
        metadata={
            "color": "green",
            "icon": "check-circle",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 1,
            "http_status": 200,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="unhealthy",
        label="Unhealthy",
        description="System has detected issues that may affect functionality",
        metadata={
            "color": "red",
            "icon": "x-circle",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 2,
            "http_status": 503,
        },
        category=ChoiceCategory.STATUS,
    ),
]

# Simple Health Check Status Choices
SIMPLE_HEALTH_STATUSES = [
    RichChoice(
        value="ok",
        label="OK",
        description="Basic health check passed",
        metadata={
            "color": "green",
            "icon": "check",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 1,
            "http_status": 200,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="error",
        label="Error",
        description="Basic health check failed",
        metadata={
            "color": "red",
            "icon": "x",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 2,
            "http_status": 500,
        },
        category=ChoiceCategory.STATUS,
    ),
]

# Entity Type Choices for Search
ENTITY_TYPES = [
    RichChoice(
        value="park",
        label="Park",
        description="Theme parks and amusement parks",
        metadata={
            "color": "green",
            "icon": "map-pin",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 1,
            "search_weight": 1.0,
        },
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="ride",
        label="Ride",
        description="Individual rides and attractions",
        metadata={
            "color": "blue",
            "icon": "activity",
            "css_class": "bg-blue-100 text-blue-800",
            "sort_order": 2,
            "search_weight": 1.0,
        },
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="company",
        label="Company",
        description="Manufacturers, operators, and designers",
        metadata={
            "color": "purple",
            "icon": "building",
            "css_class": "bg-purple-100 text-purple-800",
            "sort_order": 3,
            "search_weight": 0.8,
        },
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="user",
        label="User",
        description="User profiles and accounts",
        metadata={
            "color": "orange",
            "icon": "user",
            "css_class": "bg-orange-100 text-orange-800",
            "sort_order": 4,
            "search_weight": 0.5,
        },
        category=ChoiceCategory.CLASSIFICATION,
    ),
]

# ============================================================================
# Severity Levels (used by ApplicationError, SystemAlert, Incident, RequestMetadata)
# ============================================================================
SEVERITY_LEVELS = [
    RichChoice(
        value="critical",
        label="Critical",
        description="Critical issue requiring immediate attention",
        metadata={
            "color": "red",
            "icon": "alert-octagon",
            "css_class": "bg-red-100 text-red-800 border-red-300",
            "sort_order": 1,
            "priority": 1,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="high",
        label="High",
        description="High priority issue",
        metadata={
            "color": "orange",
            "icon": "alert-triangle",
            "css_class": "bg-orange-100 text-orange-800 border-orange-300",
            "sort_order": 2,
            "priority": 2,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="medium",
        label="Medium",
        description="Medium priority issue",
        metadata={
            "color": "yellow",
            "icon": "info",
            "css_class": "bg-yellow-100 text-yellow-800 border-yellow-300",
            "sort_order": 3,
            "priority": 3,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="low",
        label="Low",
        description="Low priority issue",
        metadata={
            "color": "blue",
            "icon": "info",
            "css_class": "bg-blue-100 text-blue-800 border-blue-300",
            "sort_order": 4,
            "priority": 4,
        },
        category=ChoiceCategory.PRIORITY,
    ),
]

# Extended severity levels including debug/info/warning/error for RequestMetadata
REQUEST_SEVERITY_LEVELS = [
    RichChoice(
        value="debug",
        label="Debug",
        description="Debug-level information",
        metadata={
            "color": "gray",
            "icon": "bug",
            "css_class": "bg-gray-100 text-gray-800",
            "sort_order": 1,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="info",
        label="Info",
        description="Informational message",
        metadata={
            "color": "blue",
            "icon": "info",
            "css_class": "bg-blue-100 text-blue-800",
            "sort_order": 2,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="warning",
        label="Warning",
        description="Warning condition",
        metadata={
            "color": "yellow",
            "icon": "alert-triangle",
            "css_class": "bg-yellow-100 text-yellow-800",
            "sort_order": 3,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="error",
        label="Error",
        description="Error condition",
        metadata={
            "color": "red",
            "icon": "x-circle",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 4,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="critical",
        label="Critical",
        description="Critical error requiring immediate attention",
        metadata={
            "color": "red",
            "icon": "alert-octagon",
            "css_class": "bg-red-200 text-red-900 font-bold",
            "sort_order": 5,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# Error/Request Sources
# ============================================================================
ERROR_SOURCES = [
    RichChoice(
        value="frontend",
        label="Frontend",
        description="Error originated from frontend application",
        metadata={
            "color": "purple",
            "icon": "monitor",
            "css_class": "bg-purple-100 text-purple-800",
            "sort_order": 1,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="backend",
        label="Backend",
        description="Error originated from backend server",
        metadata={
            "color": "blue",
            "icon": "server",
            "css_class": "bg-blue-100 text-blue-800",
            "sort_order": 2,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="api",
        label="API",
        description="Error originated from API layer",
        metadata={
            "color": "green",
            "icon": "code",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 3,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# System Alert Types
# ============================================================================
SYSTEM_ALERT_TYPES = [
    RichChoice(
        value="orphaned_images",
        label="Orphaned Images",
        description="Images not associated with any entity",
        metadata={"color": "orange", "icon": "image", "sort_order": 1},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="stale_submissions",
        label="Stale Submissions",
        description="Submissions pending for too long",
        metadata={"color": "yellow", "icon": "clock", "sort_order": 2},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="circular_dependency",
        label="Circular Dependency",
        description="Detected circular reference in data",
        metadata={"color": "red", "icon": "refresh-cw", "sort_order": 3},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="validation_error",
        label="Validation Error",
        description="Data validation failure",
        metadata={"color": "red", "icon": "alert-circle", "sort_order": 4},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="ban_attempt",
        label="Ban Attempt",
        description="User ban action was triggered",
        metadata={"color": "red", "icon": "shield-off", "sort_order": 5},
        category=ChoiceCategory.SECURITY,
    ),
    RichChoice(
        value="upload_timeout",
        label="Upload Timeout",
        description="File upload exceeded time limit",
        metadata={"color": "orange", "icon": "upload-cloud", "sort_order": 6},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="high_error_rate",
        label="High Error Rate",
        description="Elevated error rate detected",
        metadata={"color": "red", "icon": "trending-up", "sort_order": 7},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="database_connection",
        label="Database Connection",
        description="Database connectivity issue",
        metadata={"color": "red", "icon": "database", "sort_order": 8},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="memory_usage",
        label="Memory Usage",
        description="High memory consumption detected",
        metadata={"color": "orange", "icon": "cpu", "sort_order": 9},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="queue_backup",
        label="Queue Backup",
        description="Task queue is backing up",
        metadata={"color": "yellow", "icon": "layers", "sort_order": 10},
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# Metric Types for Rate Limiting
# ============================================================================
METRIC_TYPES = [
    RichChoice(
        value="block_rate",
        label="Block Rate",
        description="Percentage of requests being blocked",
        metadata={"color": "red", "icon": "shield", "sort_order": 1},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="total_requests",
        label="Total Requests",
        description="Total number of requests",
        metadata={"color": "blue", "icon": "activity", "sort_order": 2},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="unique_ips",
        label="Unique IPs",
        description="Number of unique IP addresses",
        metadata={"color": "purple", "icon": "globe", "sort_order": 3},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="function_specific",
        label="Function Specific",
        description="Metrics for a specific function",
        metadata={"color": "green", "icon": "code", "sort_order": 4},
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# Incident Statuses
# ============================================================================
INCIDENT_STATUSES = [
    RichChoice(
        value="open",
        label="Open",
        description="Incident is open and awaiting investigation",
        metadata={
            "color": "red",
            "icon": "alert-circle",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 1,
            "is_active": True,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="investigating",
        label="Investigating",
        description="Incident is being actively investigated",
        metadata={
            "color": "yellow",
            "icon": "search",
            "css_class": "bg-yellow-100 text-yellow-800",
            "sort_order": 2,
            "is_active": True,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="resolved",
        label="Resolved",
        description="Incident has been resolved",
        metadata={
            "color": "green",
            "icon": "check-circle",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 3,
            "is_active": False,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="closed",
        label="Closed",
        description="Incident is closed",
        metadata={
            "color": "gray",
            "icon": "x-circle",
            "css_class": "bg-gray-100 text-gray-800",
            "sort_order": 4,
            "is_active": False,
        },
        category=ChoiceCategory.STATUS,
    ),
]

# ============================================================================
# Alert Sources
# ============================================================================
ALERT_SOURCES = [
    RichChoice(
        value="system",
        label="System Alert",
        description="Alert from system monitoring",
        metadata={"color": "blue", "icon": "server", "sort_order": 1},
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="rate_limit",
        label="Rate Limit Alert",
        description="Alert from rate limiting system",
        metadata={"color": "orange", "icon": "shield", "sort_order": 2},
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# Pipeline Error Severities
# ============================================================================
PIPELINE_ERROR_SEVERITIES = [
    RichChoice(
        value="critical",
        label="Critical",
        description="Critical pipeline failure requiring immediate attention",
        metadata={
            "color": "red",
            "icon": "alert-octagon",
            "css_class": "bg-red-100 text-red-800 border-red-300",
            "sort_order": 1,
            "priority": 1,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="error",
        label="Error",
        description="Pipeline error that needs investigation",
        metadata={
            "color": "orange",
            "icon": "alert-triangle",
            "css_class": "bg-orange-100 text-orange-800 border-orange-300",
            "sort_order": 2,
            "priority": 2,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="warning",
        label="Warning",
        description="Pipeline warning that may need attention",
        metadata={
            "color": "yellow",
            "icon": "alert-circle",
            "css_class": "bg-yellow-100 text-yellow-800 border-yellow-300",
            "sort_order": 3,
            "priority": 3,
        },
        category=ChoiceCategory.PRIORITY,
    ),
    RichChoice(
        value="info",
        label="Info",
        description="Informational pipeline event",
        metadata={
            "color": "blue",
            "icon": "info",
            "css_class": "bg-blue-100 text-blue-800 border-blue-300",
            "sort_order": 4,
            "priority": 4,
        },
        category=ChoiceCategory.PRIORITY,
    ),
]

# ============================================================================
# Anomaly Types
# ============================================================================
ANOMALY_TYPES = [
    RichChoice(
        value="spike",
        label="Spike",
        description="Sudden increase in metric value",
        metadata={
            "color": "red",
            "icon": "trending-up",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 1,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="drop",
        label="Drop",
        description="Sudden decrease in metric value",
        metadata={
            "color": "blue",
            "icon": "trending-down",
            "css_class": "bg-blue-100 text-blue-800",
            "sort_order": 2,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="trend_change",
        label="Trend Change",
        description="Change in the overall trend direction",
        metadata={
            "color": "yellow",
            "icon": "activity",
            "css_class": "bg-yellow-100 text-yellow-800",
            "sort_order": 3,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="outlier",
        label="Outlier",
        description="Value outside normal distribution",
        metadata={
            "color": "purple",
            "icon": "git-branch",
            "css_class": "bg-purple-100 text-purple-800",
            "sort_order": 4,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
    RichChoice(
        value="threshold_breach",
        label="Threshold Breach",
        description="Value exceeded configured threshold",
        metadata={
            "color": "orange",
            "icon": "alert-triangle",
            "css_class": "bg-orange-100 text-orange-800",
            "sort_order": 5,
        },
        category=ChoiceCategory.TECHNICAL,
    ),
]

# ============================================================================
# Cleanup Job Statuses
# ============================================================================
CLEANUP_JOB_STATUSES = [
    RichChoice(
        value="success",
        label="Success",
        description="Cleanup job completed successfully",
        metadata={
            "color": "green",
            "icon": "check-circle",
            "css_class": "bg-green-100 text-green-800",
            "sort_order": 1,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="failed",
        label="Failed",
        description="Cleanup job failed with errors",
        metadata={
            "color": "red",
            "icon": "x-circle",
            "css_class": "bg-red-100 text-red-800",
            "sort_order": 2,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="partial",
        label="Partial",
        description="Cleanup job completed with some failures",
        metadata={
            "color": "yellow",
            "icon": "alert-circle",
            "css_class": "bg-yellow-100 text-yellow-800",
            "sort_order": 3,
        },
        category=ChoiceCategory.STATUS,
    ),
    RichChoice(
        value="skipped",
        label="Skipped",
        description="Cleanup job was skipped",
        metadata={
            "color": "gray",
            "icon": "skip-forward",
            "css_class": "bg-gray-100 text-gray-800",
            "sort_order": 4,
        },
        category=ChoiceCategory.STATUS,
    ),
]

# ============================================================================
# Date Precision (shared across multiple domains)
# ============================================================================
DATE_PRECISION = [
    RichChoice(
        value="exact",
        label="Exact Date",
        description="Date is known exactly",
        metadata={"color": "green", "icon": "calendar", "sort_order": 1, "format": "YYYY-MM-DD"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="month",
        label="Month and Year",
        description="Only month and year are known",
        metadata={"color": "blue", "icon": "calendar", "sort_order": 2, "format": "YYYY-MM"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="year",
        label="Year Only",
        description="Only the year is known",
        metadata={"color": "yellow", "icon": "calendar", "sort_order": 3, "format": "YYYY"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="decade",
        label="Decade",
        description="Only the decade is known",
        metadata={"color": "orange", "icon": "calendar", "sort_order": 4, "format": "YYYYs"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="century",
        label="Century",
        description="Only the century is known",
        metadata={"color": "gray", "icon": "calendar", "sort_order": 5, "format": "YYc"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
    RichChoice(
        value="approximate",
        label="Approximate",
        description="Date is approximate/estimated",
        metadata={"color": "gray", "icon": "help-circle", "sort_order": 6, "format": "~YYYY"},
        category=ChoiceCategory.CLASSIFICATION,
    ),
]


def register_core_choices():
    """Register all core system choices with the global registry"""

    register_choices(
        name="health_statuses",
        choices=HEALTH_STATUSES,
        domain="core",
        description="Health check status options",
        metadata={"domain": "core", "type": "health_status"},
    )

    register_choices(
        name="simple_health_statuses",
        choices=SIMPLE_HEALTH_STATUSES,
        domain="core",
        description="Simple health check status options",
        metadata={"domain": "core", "type": "simple_health_status"},
    )

    register_choices(
        name="entity_types",
        choices=ENTITY_TYPES,
        domain="core",
        description="Entity type classifications for search functionality",
        metadata={"domain": "core", "type": "entity_type"},
    )

    register_choices(
        name="severity_levels",
        choices=SEVERITY_LEVELS,
        domain="core",
        description="Severity levels for errors and alerts",
        metadata={"domain": "core", "type": "severity"},
    )

    register_choices(
        name="request_severity_levels",
        choices=REQUEST_SEVERITY_LEVELS,
        domain="core",
        description="Extended severity levels for request metadata",
        metadata={"domain": "core", "type": "request_severity"},
    )

    register_choices(
        name="error_sources",
        choices=ERROR_SOURCES,
        domain="core",
        description="Sources of application errors",
        metadata={"domain": "core", "type": "error_source"},
    )

    register_choices(
        name="system_alert_types",
        choices=SYSTEM_ALERT_TYPES,
        domain="core",
        description="Types of system alerts",
        metadata={"domain": "core", "type": "alert_type"},
    )

    register_choices(
        name="metric_types",
        choices=METRIC_TYPES,
        domain="core",
        description="Types of rate limit metrics",
        metadata={"domain": "core", "type": "metric_type"},
    )

    register_choices(
        name="incident_statuses",
        choices=INCIDENT_STATUSES,
        domain="core",
        description="Incident status options",
        metadata={"domain": "core", "type": "incident_status"},
    )

    register_choices(
        name="alert_sources",
        choices=ALERT_SOURCES,
        domain="core",
        description="Sources of alerts",
        metadata={"domain": "core", "type": "alert_source"},
    )

    register_choices(
        name="pipeline_error_severities",
        choices=PIPELINE_ERROR_SEVERITIES,
        domain="core",
        description="Severity levels for pipeline errors",
        metadata={"domain": "core", "type": "pipeline_error_severity"},
    )

    register_choices(
        name="anomaly_types",
        choices=ANOMALY_TYPES,
        domain="core",
        description="Types of detected anomalies",
        metadata={"domain": "core", "type": "anomaly_type"},
    )

    register_choices(
        name="cleanup_job_statuses",
        choices=CLEANUP_JOB_STATUSES,
        domain="core",
        description="Status options for cleanup jobs",
        metadata={"domain": "core", "type": "cleanup_job_status"},
    )

    register_choices(
        name="date_precision",
        choices=DATE_PRECISION,
        domain="core",
        description="Date precision options",
        metadata={"domain": "core", "type": "date_precision"},
    )


# Auto-register choices when module is imported
register_core_choices()

