# registry.py
#
# Copyright 2025 Pavel Baksy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from typing import Dict, List, Tuple, Type
from .base_exporter import BaseExporter


class ExporterRegistry:
    """Registry for managing export formats."""

    _exporters: Dict[str, Type[BaseExporter]] = {}

    @classmethod
    def register(cls, format_id: str, exporter_class: Type[BaseExporter]):
        """Register an exporter class."""
        cls._exporters[format_id] = exporter_class

    @classmethod
    def get_exporter(cls, format_id: str) -> BaseExporter:
        """Get exporter instance by format ID."""
        exporter_class = cls._exporters.get(format_id)
        if not exporter_class:
            raise ValueError(f"Unknown export format: {format_id}")
        return exporter_class()

    @classmethod
    def get_all_formats(cls) -> List[Tuple[str, str]]:
        """Get all registered formats as [(id, name), ...]."""
        return [(format_id, cls._exporters[format_id]().format_name)
                for format_id in cls._exporters.keys()]
