"""This module contains the test models of the ``broker_models_hooks`` app"""

from django.db import models

from mtp.apps.sync.models import Syncable

from mtp.apps.broker_models_hooks.models import (
    BrokerHookM2MFromMixin,
    BrokerHookM2MRelatedMixin,
    BrokerHookMixin,
)


class ModelWithBrokerHook(BrokerHookMixin, models.Model):
    """A test model who inherit from ``BrokerHookMixin``"""

    def get_broker_topic(self):
        """Get the broker topic for this model"""

        return 'test_topic'

    def get_serialized_representation(self):
        """Get the serialized representation for this model"""

        from .serialializers import ModelWithBrokerHookSerializer  # Avoid circular imports

        return ModelWithBrokerHookSerializer(self).data


class SyncableModelWithBrokerHook(BrokerHookMixin, Syncable):
    """A test model who inherit from ``BrokerHookMixin`` and ``Syncable``"""

    def get_broker_topic(self):
        """Get the broker topic for this model"""

        return 'test_topic'

    def get_serialized_representation(self):
        """Get the serialized representation for this model"""

        from .serialializers import SyncableModelWithBrokerHookSerializer  # Avoid circular imports

        return SyncableModelWithBrokerHookSerializer(self).data


class ModelWithBrokerHookM2MRelatedMixin(BrokerHookM2MRelatedMixin, models.Model):
    """A test model who inherit from ``BrokerHookM2MRelatedMixin``"""

    # pylint: disable=missing-param-doc,missing-type-doc
    def get_modelwithm2m_broker_topic(self, from_instance):
        """Get the broker topic for this model

        Parameters
        ----------
        from_instance: ModelWithM2M

        """

        return 'test_topic_m2m/%s' % from_instance.pk

    def get_serialized_representation(self):
        """Get the serialized representation for this model"""

        # Avoid circular imports
        from .serialializers import ModelWithBrokerHookM2MRelatedMixinSerializer

        return ModelWithBrokerHookM2MRelatedMixinSerializer(self).data


class ModelWithM2M(BrokerHookM2MFromMixin, models.Model):
    """A test model with a m2m field to an instance who inherit from ``BrokerHookM2MRelatedMixin"""

    things = models.ManyToManyField(ModelWithBrokerHookM2MRelatedMixin)
