"""
Concrete implementations of console interfaces for production use.
"""

from typing import Any

from .console_interfaces import (
    ConfigProvider,
    ConsoleFactory,
    ProgressFactory,
    RichComponentFactory,
    SafetyProvider,
    SyntaxFactory,
    ThemeProvider,
)


class RichConsoleFactory(ConsoleFactory):
    """Factory for creating Rich Console instances."""

    def create_console(
        self, theme: Any, force_terminal: bool, legacy_windows: bool, safe_box: bool, stderr: bool
    ) -> Any:
        """Create a Rich Console instance."""
        from rich.console import Console

        return Console(
            theme=theme,
            force_terminal=force_terminal,
            legacy_windows=legacy_windows,
            safe_box=safe_box,
            stderr=stderr,
        )


class RichSyntaxFactory(SyntaxFactory):
    """Factory for creating Rich Syntax instances."""

    def create_syntax(self, code: str, language: str, theme: str) -> Any:
        """Create a Rich Syntax instance."""
        from rich.syntax import Syntax

        return Syntax(code, language, theme=theme)


class RichProgressFactory(ProgressFactory):
    """Factory for creating Rich Progress instances."""

    def create_progress(
        self, *columns: Any, console: Any = None, refresh_per_second: float = 10
    ) -> Any:
        """Create a Rich Progress instance."""
        from rich.progress import Progress

        return Progress(*columns, console=console, refresh_per_second=refresh_per_second)

    def create_spinner_column(self) -> Any:
        """Create a spinner column."""
        from rich.progress import SpinnerColumn

        return SpinnerColumn()

    def create_text_column(self, text_format: str) -> Any:
        """Create a text column."""
        from rich.progress import TextColumn

        return TextColumn(text_format)

    def create_bar_column(self) -> Any:
        """Create a bar column."""
        from rich.progress import BarColumn

        return BarColumn()


class DefaultRichComponentFactory(RichComponentFactory):
    """Factory for creating various Rich components."""

    def create_table(
        self,
        title: str | None = None,
        show_header: bool = True,
        header_style: str | None = None,
    ) -> Any:
        """Create a Rich Table instance."""
        from rich.table import Table

        return Table(title=title, show_header=show_header, header_style=header_style)

    def create_panel(
        self,
        content: Any,
        title: str | None = None,
        style: Any = None,
        padding: tuple[int, int] = (0, 1),
    ) -> Any:
        """Create a Rich Panel instance."""
        from rich.panel import Panel

        return Panel(content, title=title, style=style, padding=padding)

    def create_text(self, text: str, style: Any = None) -> Any:
        """Create a Rich Text instance."""
        from rich.text import Text

        return Text(text, style=style)

    def create_columns(self, renderables: list[Any]) -> Any:
        """Create Rich Columns layout."""
        from rich.columns import Columns

        return Columns(renderables)

    def create_layout(self) -> Any:
        """Create a Rich Layout instance."""
        from rich.layout import Layout

        return Layout()

    def create_live(self, renderable: Any, console: Any, refresh_per_second: float = 4) -> Any:
        """Create a Rich Live display instance."""
        from rich.live import Live

        return Live(renderable, console=console, refresh_per_second=refresh_per_second)


class DefaultThemeProvider(ThemeProvider):
    """Default theme provider using Storm themes."""

    def get_theme(self, theme_name: str) -> Any:
        """Get theme configuration by name."""
        from .themes import get_theme

        return get_theme(theme_name)


class DefaultConfigProvider(ConfigProvider):
    """Default config provider using Storm config."""

    def get_config(self) -> Any:
        """Get current configuration."""
        from ..config import get_config

        return get_config()


class DefaultSafetyProvider(SafetyProvider):
    """Default safety provider."""

    def get_safety_wrapper(self) -> Any:
        """Get the safety wrapper instance."""
        from .safety import SafeConsoleWrapper

        return SafeConsoleWrapper()
