"""
Configuration settings for alert processor service.
"""

import os
from shared.config.base import BaseServiceSettings


class Settings(BaseServiceSettings):
    """Application settings"""

    # Service info - override defaults
    SERVICE_NAME: str = "alert-processor"
    APP_NAME: str = "Alert Processor Service"
    DESCRIPTION: str = "Central alert and recommendation processor"
    VERSION: str = "2.0.0"

    # Alert processor specific settings
    RABBITMQ_EXCHANGE: str = "events.exchange"
    RABBITMQ_QUEUE: str = "alert_processor.queue"
    REDIS_SSE_PREFIX: str = "alerts"
    ORCHESTRATOR_TIMEOUT: int = 10
    NOTIFICATION_TIMEOUT: int = 5
    CACHE_ENABLED: bool = True
    CACHE_TTL_SECONDS: int = 300

    @property
    def NOTIFICATION_URL(self) -> str:
        """Get notification service URL for backwards compatibility"""
        return self.NOTIFICATION_SERVICE_URL

    # Database configuration (secure approach - build from components)
    @property
    def DATABASE_URL(self) -> str:
        """Build database URL from secure components"""
        # Try complete URL first (for backward compatibility)
        complete_url = os.getenv("ALERT_PROCESSOR_DATABASE_URL")
        if complete_url:
            return complete_url

        # Build from components (secure approach)
        user = os.getenv("ALERT_PROCESSOR_DB_USER", "alert_processor_user")
        password = os.getenv("ALERT_PROCESSOR_DB_PASSWORD", "alert_processor_pass123")
        host = os.getenv("ALERT_PROCESSOR_DB_HOST", "alert-processor-db-service")
        port = os.getenv("ALERT_PROCESSOR_DB_PORT", "5432")
        name = os.getenv("ALERT_PROCESSOR_DB_NAME", "alert_processor_db")

        return f"postgresql+asyncpg://{user}:{password}@{host}:{port}/{name}"


settings = Settings()
