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

from collections.abc import Callable
from typing import Any
from django.contrib import admin

from .models import Ticket, TicketPriority, TicketTag


class TicketAdmin(admin.ModelAdmin):

    list_display = ["uuid", "title", "get_author_name", "get_priority_title", "get_tags_count"]

    @admin.display(description="Author", ordering="author__name")
    def get_author_name(self, obj):
        return obj.author.fullname if obj.author else None

    @admin.display(description="Priority", ordering="priority__title")
    def get_priority_title(self, obj):
        return obj.priority.title if obj.priority else None

    @admin.display(description="Tags")
    def get_tags_count(self, obj):
        return obj.tags.count()


class TicketPriorityAdmin(admin.ModelAdmin):

    list_display = ["uuid", "title", "colour", "backgroundcolour", "get_used_count"]

    @admin.display(description="Used by")
    def get_used_count(self, obj):
        return Ticket.objects.filter(priority=obj).count()


class TicketTagAdmin(admin.ModelAdmin):

    list_display = ["uuid", "title", "colour", "backgroundcolour", "get_used_count"]

    @admin.display(description="Used by")
    def get_used_count(self, obj):
        return Ticket.objects.filter(tags__in=[obj]).count()


admin.site.register(Ticket, TicketAdmin)
admin.site.register(TicketPriority, TicketPriorityAdmin)
admin.site.register(TicketTag, TicketTagAdmin)
