from django.contrib.auth.mixins import UserPassesTestMixin


class ChefRequiredMixin(UserPassesTestMixin):
    def test_func(self):
        user = self.request.user
        return (user is not None) and hasattr(user, "profile") and user.profile.is_chef


class ChefEventRequiredMixin(UserPassesTestMixin):
    def test_func(self):
        user = self.request.user
        is_chef = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef
        )
        is_chef_event = (
            (user is not None)
            and hasattr(user, "profile")
            and user.profile.is_chef_event
        )
        return is_chef or is_chef_event


class ChefInstruRequiredMixin(UserPassesTestMixin):
    def test_func(self):
        user = self.request.user
        is_chef = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef
        )
        is_chef_instru = (
            (user is not None)
            and hasattr(user, "profile")
            and user.profile.is_chef_instru
        )
        return is_chef or is_chef_instru


class ChefComRequiredMixin(UserPassesTestMixin):
    def test_func(self):
        user = self.request.user
        is_chef = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef
        )
        is_chef_com = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com
        )
        return is_chef or is_chef_com


class AllChefRequiredMixin(UserPassesTestMixin):
    def test_func(self):
        user = self.request.user
        is_chef = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef
        )
        is_su = (user is not None) and user.is_superuser
        is_chef_com = (
            (user is not None) and hasattr(user, "profile") and user.profile.is_chef_com
        )
        is_chef_event = (
            (user is not None)
            and hasattr(user, "profile")
            and user.profile.is_chef_event
        )
        return is_chef or is_chef_com or is_chef_event or is_su
