from django.contrib.auth.models import User
from rest_framework import serializers
from main.models import UserProfile
from access_controller.settings import ZENDESK_ROLES


class UserSerializer(serializers.HyperlinkedModelSerializer):
    """
    Класс serializer для модели User.
    """
    class Meta:
        model = User
        fields = ['email']


class ProfileSerializer(serializers.HyperlinkedModelSerializer):
    """Класс serializer для модели профиля пользователя"""
    user = UserSerializer()

    class Meta:
        model = UserProfile
        fields = ['user', 'id', 'name', 'zendesk_role']


class ZendeskUserSerializer(serializers.Serializer):
    """Класс serializer для объектов пользователей из zenpy"""
    name = serializers.CharField()
    zendesk_role = serializers.SerializerMethodField('get_zendesk_role')
    email = serializers.EmailField()

    @staticmethod
    def get_zendesk_role(obj):
        if obj.custom_role_id == ZENDESK_ROLES['engineer']:
            return 'engineer'
        elif obj.custom_role_id == ZENDESK_ROLES['light_agent']:
            return 'light_agent'
        else:
            return "empty"
