"""
Celery Configuration Settings - Simplified
"""
import os
from typing import List
from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict


class CelerySettings(BaseSettings):
    """Simplified Celery configuration with environment variable support"""
    
    # Essential Configuration (from environment)
    CELERY_BROKER_URL: str = Field(
        default="amqp://guest:guest@rabbitmq:5672//",
        description="Celery broker URL (RabbitMQ)"
    )
    
    CELERY_RESULT_BACKEND: str = Field(
        default="redis://redis:6379/0",
        description="Celery result backend URL (Redis)"
    )
    
    CELERY_TASK_DEFAULT_QUEUE: str = Field(
        default="default",
        description="Default queue name for tasks"
    )
    
    CELERY_TASK_ALWAYS_EAGER: bool = Field(
        default=False,
        description="Execute tasks locally instead of sending to queue (for testing)"
    )
    
    CELERY_LOG_LEVEL: str = Field(
        default="INFO",
        description="Celery logging level"
    )
    
    model_config = SettingsConfigDict(
        env_file=".env",
        case_sensitive=True,
        extra="ignore"
    )
    
    def get_celery_config(self) -> dict:
        """
        Get Celery configuration dictionary with sensible defaults
        
        Returns:
            dict: Celery configuration settings
        """
        return {
            # Core Configuration
            "broker_url": self.CELERY_BROKER_URL,
            "result_backend": self.CELERY_RESULT_BACKEND,
            
            # Task Settings with Defaults
            "task_default_queue": self.CELERY_TASK_DEFAULT_QUEUE,
            "task_serializer": "json",
            "result_serializer": "json",
            "accept_content": ["json"],
            
            # Timezone and UTC
            "timezone": "UTC",
            "enable_utc": True,
            
            # Testing Configuration
            "task_always_eager": self.CELERY_TASK_ALWAYS_EAGER,
            "task_eager_propagates": True,
            
            # Module Discovery
            "imports": ["src.worker.tasks"],
            "include": ["src.worker.tasks"],
            
            # Future-ready settings (with sensible defaults)
            "task_acks_late": True,
            "task_reject_on_worker_lost": True,
            "worker_prefetch_multiplier": 1,
            "result_expires": 3600,  # 1 hour
        }


# Global celery settings instance
celery_settings = CelerySettings()