from typing import Type

from edpdependencyinjection import AnyType
from messagebus import SubscriptionInfo


class EventProcessorDefinition:
    """Definition for an event processor with its subscription type.

    Args:
        processor_type: The processor type to be resolved from the DI context.
        subscription_type: Must be one of SubscriptionInfo.TYPE_REENTRANT (1)
            or SubscriptionInfo.TYPE_NON_REENTRANT (2).
    """

    VALID_SUBSCRIPTION_TYPES = (SubscriptionInfo.TYPE_REENTRANT, SubscriptionInfo.TYPE_NON_REENTRANT)

    def __init__(
        self,
        processor_type: Type[AnyType],
        subscription_type: int
    ):
        if subscription_type not in self.VALID_SUBSCRIPTION_TYPES:
            raise ValueError(
                f"subscription_type must be SubscriptionInfo.TYPE_REENTRANT (1) "
                f"or SubscriptionInfo.TYPE_NON_REENTRANT (2), got {subscription_type}"
            )
        self.processor_type = processor_type
        self.subscription_type = subscription_type

    def __str__(self):
        return f"Processor: {self.processor_type} - {self.subscription_type}"
