"""
애플리케이션 설정 관리
"""
import os
from typing import List
from pydantic import BaseSettings
from dotenv import load_dotenv

# .env 파일 로드
load_dotenv()


class Settings(BaseSettings):
    """애플리케이션 설정"""

    # API 서버 설정
    api_host: str = "localhost"
    api_port: int = 8000

    # 프론트엔드 설정  
    frontend_host: str = "localhost"
    frontend_port: int = 8501

    # 강화학습 하이퍼파라미터
    default_learning_rate: float = 0.1
    default_discount_factor: float = 0.9
    default_epsilon: float = 0.1

    # 협상 환경 설정
    default_anchor_price: int = 100
    max_episodes: int = 1000
    max_steps_per_episode: int = 10

    # 로깅 설정
    log_level: str = "INFO"
    log_file: str = "app.log"

    # CORS 설정
    allowed_origins: List[str] = ["http://localhost:8501", "http://127.0.0.1:8501"]

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 환경 변수로부터 값 로드
        self.api_host = os.getenv("API_HOST", self.api_host)
        self.api_port = int(os.getenv("API_PORT", str(self.api_port)))
        self.frontend_host = os.getenv("FRONTEND_HOST", self.frontend_host)
        self.frontend_port = int(os.getenv("FRONTEND_PORT", str(self.frontend_port)))
        self.default_learning_rate = float(os.getenv("DEFAULT_LEARNING_RATE", str(self.default_learning_rate)))
        self.default_discount_factor = float(os.getenv("DEFAULT_DISCOUNT_FACTOR", str(self.default_discount_factor)))
        self.default_epsilon = float(os.getenv("DEFAULT_EPSILON", str(self.default_epsilon)))
        self.default_anchor_price = int(os.getenv("DEFAULT_ANCHOR_PRICE", str(self.default_anchor_price)))
        self.max_episodes = int(os.getenv("MAX_EPISODES", str(self.max_episodes)))
        self.max_steps_per_episode = int(os.getenv("MAX_STEPS_PER_EPISODE", str(self.max_steps_per_episode)))
        self.log_level = os.getenv("LOG_LEVEL", self.log_level)
        self.log_file = os.getenv("LOG_FILE", self.log_file)

    class Config:
        env_file = ".env"


# 전역 설정 인스턴스
settings = Settings()
