from pydantic import BaseModel

DEFAULT_WEBSOCKET_HOST = "0.0.0.0"
DEFAULT_WEBSOCKET_PORT = 8765

DEFAULT_MIN_GRID_SIZE = 12
DEFAULT_MAX_GRID_SIZE = 25

DEFAULT_GRID_BLOCK_RATIO = 0.41

DEFAULT_MAX_SESSION_IDLE_TIME_SECONDS = 3600 * 48  # 2 days



class ServerConfig(BaseModel): 
    
    @classmethod
    def setup(cls,
              min_grid_size: int = DEFAULT_MIN_GRID_SIZE,
              max_grid_size: int = DEFAULT_MAX_GRID_SIZE,
              max_session_idle_time_seconds: int = DEFAULT_MAX_SESSION_IDLE_TIME_SECONDS,
              grid_block_ratio: float = DEFAULT_GRID_BLOCK_RATIO,
              host: str = DEFAULT_WEBSOCKET_HOST,
              port: int = DEFAULT_WEBSOCKET_PORT
              ) -> "ServerConfig":
        cls._singleton = cls(
            MIN_GRID_SIZE=min_grid_size,
            MAX_GRID_SIZE=max_grid_size,
            MAX_SESSION_IDLE_TIME_SECONDS=max_session_idle_time_seconds,
            GRID_BLOCK_RATIO=grid_block_ratio,
            HOST=host,
            PORT=port,
        )

        return cls._singleton
    
    @classmethod
    def get_config(cls) -> "ServerConfig":
        if not hasattr(cls, "_singleton"):
            raise ValueError("ServerConfig singleton not initialized. Call setup() first.")
        return cls._singleton

    MAX_GRID_SIZE: int
    MIN_GRID_SIZE: int
    MAX_SESSION_IDLE_TIME_SECONDS: int
    GRID_BLOCK_RATIO: float
    HOST: str
    PORT: int


