"""The Mimeo Consumer module.

It exports only one class:
    * Consumer
        An abstract class for data consumers in Mimeo.
"""
from __future__ import annotations

from abc import ABCMeta, abstractmethod
from typing import Collection, Generator


class Consumer(metaclass=ABCMeta):
    """An abstract class for data consumers in Mimeo.

    Its subclasses are meant to be used in the Mimeo processing.
    Every supported output direction has a Consumer representation.

    Methods
    -------
    consume
        Consumes data generated by Mimeo.
    """

    @classmethod
    def __subclasshook__(
            cls,
            subclass: Consumer,
    ):
        """Verify if a subclass implements all abstract methods.

        Parameters
        ----------
        subclass : Consumer
            A Consumer subclass

        Returns
        -------
        bool
            True if the subclass includes the consume method
        """
        return "consume" in subclass.__dict__ and callable(subclass.consume)

    @abstractmethod
    def consume(
            self,
            data: Collection | Generator,
    ):
        """Consume data generated by Mimeo.

        It is an abstract method to implement in subclasses

        Parameters
        ----------
        data : Collection | Generator
            Stringified data generated by Mimeo
        """
        raise NotImplementedError
