# -*- encoding: utf-8 -*-

from django.apps import apps
from django.conf import settings
from rest_framework import serializers

from apps.home.models import Ticket, TicketPriority, TicketTag
from apps.authentication.models import Department


class DepartmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = Department
        fields = [
            "uuid", "title", "icon"
        ]


class UserSerializer(serializers.ModelSerializer):
    department = DepartmentSerializer()

    class Meta:
        model = apps.get_model(settings.AUTH_USER_MODEL)
        fields = [
            "uuid", "icon", "email", "forename", "surname", "department",
            "create_timestamp", "edit_timestamp"
        ]


class TicketPrioritySerializer(serializers.ModelSerializer):
    class Meta:
        model = TicketPriority
        fields = [
            "uuid", "title", "colour", "backgroundcolour"
        ]


class TicketTagSerializer(serializers.ModelSerializer):
    class Meta:
        model = TicketTag
        fields = [
            "uuid", "title", "colour", "backgroundcolour"
        ]


class TicketSerializer(serializers.ModelSerializer):
    author = UserSerializer()
    priority = TicketPrioritySerializer()
    tags = TicketTagSerializer(many=True)

    class Meta:
        model = Ticket
        fields = [
            "uuid", "title", "description", "author", "create_timestamp",
            "edit_timestamp", "is_edited", "was_yesterday", "is_older_than_day",
            "timestamp", "priority", "tags",
        ]
