"""
Stage registry for worker.

Single Responsibility: Map job types to stage processors (factory pattern).
"""

from .stage_adapters import (
    DiscountStageAdapter,
    GenerateStageAdapter,
    K8sStageAdapter,
    MetadataStageAdapter,
    StageProcessor,
    TimeShiftAdapter,
    UploadGeneratedAdapter,
    UsageStageAdapter,
)


class StageRegistry:
    """
    Factory for stage processors.

    Maps job types to appropriate stage adapters.
    """

    def __init__(self):
        """Initialize processor mappings."""
        self._processors = {
            "k8s": self._create_k8s_processor,
            "generate": self._create_generate_processor,
            "metadata": self._create_metadata_processor,
            "usage": self._create_usage_processor,
            "discount": self._create_discount_processor,
            "upload_generated": self._create_upload_generated_processor,
            "time_shift": self._create_time_shift_processor,
        }

    def get_processor(self, job_type: str) -> StageProcessor:
        """
        Get processor for job type.

        Args:
            job_type: Type of job (k8s, generate, etc.)

        Returns:
            Stage processor instance

        Raises:
            ValueError: If job type unknown
        """
        if job_type not in self._processors:
            raise ValueError(
                f"Unknown job type: {job_type}. "
                f"Valid types: {list(self._processors.keys())}"
            )

        factory = self._processors[job_type]
        return factory()

    def _create_k8s_processor(self) -> StageProcessor:
        """Create k8s processor."""
        return K8sStageAdapter()

    def _create_generate_processor(self) -> StageProcessor:
        """Create generate processor."""
        return GenerateStageAdapter()

    def _create_metadata_processor(self) -> StageProcessor:
        """Create metadata processor."""
        return MetadataStageAdapter()

    def _create_usage_processor(self) -> StageProcessor:
        """Create usage processor."""
        return UsageStageAdapter()

    def _create_discount_processor(self) -> StageProcessor:
        """Create discount processor."""
        return DiscountStageAdapter()

    def _create_upload_generated_processor(self) -> StageProcessor:
        """Create upload_generated processor."""
        return UploadGeneratedAdapter()

    def _create_time_shift_processor(self) -> StageProcessor:
        """Create time_shift processor."""
        return TimeShiftAdapter()
