"""This module holds mixins for the ``api`` app."""

from rest_framework.mixins import DestroyModelMixin

from mtp.apps.sync.models import Syncable


class SoftDestroyModelMixin(DestroyModelMixin):
    """Override ``DestroyModelMixin`` to handle soft-deletion of ``Syncable`` instance."""

    def perform_destroy(self, instance):
        """Soft-delete ``Syncable`` instances and perform destroy others instances."""

        if isinstance(instance, Syncable):
            instance.remove()
        else:
            super().perform_destroy(instance)
