# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later

from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from .models import Participation, Passage, Pool, Solution, Synthesis, Team, Tournament


@admin.register(Team)
class TeamAdmin(admin.ModelAdmin):
    list_display = ('name', 'trigram', 'valid',)
    search_fields = ('name', 'trigram',)
    list_filter = ('participation__valid',)

    def valid(self, team):
        return team.participation.valid

    valid.short_description = _('valid')


@admin.register(Participation)
class ParticipationAdmin(admin.ModelAdmin):
    list_display = ('team', 'valid',)
    search_fields = ('team__name', 'team__trigram',)
    list_filter = ('valid',)


@admin.register(Pool)
class PoolAdmin(admin.ModelAdmin):
    search_fields = ('participations__team__name', 'participations__team__trigram',)


@admin.register(Passage)
class PassageAdmin(admin.ModelAdmin):
    search_fields = ('pool__participations__team__name', 'pool__participations__team__trigram',)


@admin.register(Solution)
class SolutionAdmin(admin.ModelAdmin):
    list_display = ('participation',)
    search_fields = ('participation__team__name', 'participation__team__trigram',)


@admin.register(Synthesis)
class SynthesisAdmin(admin.ModelAdmin):
    list_display = ('participation',)
    search_fields = ('participation__team__name', 'participation__team__trigram',)


@admin.register(Tournament)
class TournamentAdmin(admin.ModelAdmin):
    list_display = ('name',)
    search_fields = ('name',)
