from typing import Dict, Type


from .AttestationEngine import AttestationEngine
from .AttestationEngineType import AttestationEngineType
from .AttestationEngineAmdSevSnp import AttestationEngineAmdSevSnp
from .AttestationEngineIntelTdx import AttestationEngineIntelTdx
from .AttestationExceptions import UnsupportedEngine


class AttestationEngineFactory:
    """
    Factory for instantiating attestation engine implementations.

    This class provides a centralized mapping between AttestationEngineType
    values and their corresponding concrete AttestationEngine classes.
    """


    _REGISTRY: Dict[AttestationEngineType, Type[AttestationEngine]] = {
        AttestationEngineType.AMD_SEV_SNP: AttestationEngineAmdSevSnp,
        AttestationEngineType.INTEL_TDX: AttestationEngineIntelTdx,
    }

    @classmethod
    def get(
        cls,
        engine_type: AttestationEngineType,
    ) -> AttestationEngine:
        """
        Instantiate and return an attestation engine for the requested engine_type.

        This method will:
        - Resolve the concrete AttestationEngine class associated with engine_type
        - Instantiate and return the corresponding engine instance

        Args:
        - engine_type: Attestation engine selector identifying the desired TEE backend.

        Returns:
        - An instance of the requested AttestationEngine implementation.

        Raises:
        - UnsupportedEngine: If no attestation engine is registered for engine_type.
        """
        try:
            engine_cls = cls._REGISTRY[engine_type]

        except KeyError as e:
            raise UnsupportedEngine(f"Unsupported engine type: {engine_type}") from e

        return engine_cls()
