"""
Distribution Service Configuration
"""

from shared.config.base import BaseServiceSettings
from pydantic import Field
from typing import Optional
import os


class Settings(BaseServiceSettings):
    """
    Distribution Service specific settings
    """
    
    # Service Identity
    APP_NAME: str = "Distribution Service"
    SERVICE_NAME: str = "distribution-service"
    DESCRIPTION: str = "Distribution and logistics service for enterprise tier bakery management"
    VERSION: str = "1.0.0"
    
    # Database Configuration
    # Use environment variables with fallbacks for development
    DB_HOST: str = os.getenv("DISTRIBUTION_DB_HOST", os.getenv("DB_HOST", "localhost"))
    DB_PORT: int = int(os.getenv("DISTRIBUTION_DB_PORT", os.getenv("DB_PORT", "5432")))
    DB_USER: str = os.getenv("DISTRIBUTION_DB_USER", os.getenv("DB_USER", "postgres"))
    DB_PASSWORD: str = os.getenv("DISTRIBUTION_DB_PASSWORD", os.getenv("DB_PASSWORD", "postgres"))
    DB_NAME: str = os.getenv("DISTRIBUTION_DB_NAME", os.getenv("DB_NAME", "distribution_db"))

    @property
    def DATABASE_URL(self) -> str:
        """Build database URL from components"""
        # Try service-specific environment variable first
        env_url = os.getenv("DISTRIBUTION_DATABASE_URL") or os.getenv("DATABASE_URL")
        if env_url:
            return env_url

        # Build from components
        return f"postgresql+asyncpg://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"


# Create settings instance
settings = Settings()