import typing
from apps.pos_device import models as pos_models


class POSDeviceMixin:
    """ get require objects with values in request header """

    def get_pos_device(self):
        """ get device object by device serial in request header """

        device = pos_models.Device.objects.get(
            serial=self.request.headers.get('device-serial')  # noqa
        )

        return device

    def get_device_organization(self):
        """ get device owner (organization) information """

        organization = pos_models.DeviceAssignment.objects.filter(
            device__serial=self.request.headers.get('device-serial')  # noqa
        ).first().client.organization

        return organization

    def get_provider_organization(self):
        """ get pos provider organization """

        provider = pos_models.Organization.objects.get(
            en_name=self.request.headers.get('device-provider')  # noqa
        )

        return provider

