"""Configuration and constants for ASCII Camera."""

from enum import Enum
from dataclasses import dataclass
from typing import Optional


class CharacterSet(Enum):
    """Available ASCII character sets."""
    SIMPLE = "simple"
    DETAILED = "detailed" 
    BLOCK = "block"


class ColorTheme(Enum):
    """Available color themes."""
    MATRIX = "matrix"    # Green terminal theme
    AMBER = "amber"      # Amber terminal theme  
    CYAN = "cyan"        # Cyan blue theme
    RAINBOW = "rainbow"  # Dynamic rainbow theme


@dataclass
class Config:
    """Application configuration."""
    charset: CharacterSet = CharacterSet.SIMPLE
    color_theme: Optional[ColorTheme] = None
    fps: float = 12.0
    camera_index: int = 0
    max_width: Optional[int] = None
    max_height: Optional[int] = None
    invert: bool = False
    
    def __post_init__(self):
        """Validate configuration after initialization."""
        if self.fps <= 0:
            raise ValueError("FPS must be positive")
        if self.camera_index < 0:
            raise ValueError("Camera index must be non-negative")
        if self.max_width is not None and self.max_width <= 0:
            raise ValueError("Max width must be positive")
        if self.max_height is not None and self.max_height <= 0:
            raise ValueError("Max height must be positive")


# ASCII character sets for different detail levels
ASCII_CHARS = {
    CharacterSet.SIMPLE: " .:-=+*#%@",
    CharacterSet.DETAILED: " .,'~!;<>+*xvXGM#8@", 
    CharacterSet.BLOCK: " ░▒▓█",
}

# ANSI color codes for themes
ANSI_COLORS = {
    "reset": "\033[0m",
    "black": "\033[30m",
    "red": "\033[31m", 
    "green": "\033[32m",
    "yellow": "\033[33m",
    "blue": "\033[34m",
    "magenta": "\033[35m",
    "cyan": "\033[36m",
    "white": "\033[37m",
    "bright_black": "\033[90m",
    "bright_red": "\033[91m",
    "bright_green": "\033[92m", 
    "bright_yellow": "\033[93m",
    "bright_blue": "\033[94m",
    "bright_magenta": "\033[95m",
    "bright_cyan": "\033[96m",
    "bright_white": "\033[97m",
}

# Default configuration values
DEFAULT_FPS = 12.0
DEFAULT_CHARSET = CharacterSet.SIMPLE
DEFAULT_CAMERA_INDEX = 0
DEFAULT_MAX_WIDTH = 120
DEFAULT_MAX_HEIGHT = 40
