from oscar.core.loading import get_model

from ocyan.plugin.oscar_communications.customer_extension import utils as ocyan

CommunicationEvent = get_model("order", "CommunicationEvent")


# pylint: disable=arguments-differ,unused-argument,protected-access,arguments-renamed
class Dispatcher(ocyan.Dispatcher):
    def send_email_messages(
        self, recipient_email, messages, from_email=None, attachments=None
    ):
        assert attachments is None
        return super().send_email_messages(recipient_email, messages)

    def create_communication_event(self, order, event_type, dispatched_messages):
        """
        Create order communications event for audit
        """
        if dispatched_messages and event_type is not None:
            CommunicationEvent._default_manager.create(
                order=order, event_type=event_type
            )


class BccDispatcher(Dispatcher):
    def __init__(self, bcc_admins=False, logger=None, mail_connection=None):
        super(BccDispatcher, self).__init__(
            logger=logger, mail_connection=mail_connection
        )
        self.bcc_admins = bcc_admins
