"""This module holds the django admin models for the ``evaluations`` app."""

from django.contrib import admin

from mtp.apps.common.constants import SYNC_STATUS_FIELDS

from .models import Criterion, Evaluation, Exercise, Rating


class EvaluationAdmin(admin.ModelAdmin):
    """Django admin model for the ``Evaluation`` model."""

    list_display = ('name', 'evaluation_type', 'training', 'sort_order', 'hidden')
    list_editable = ('hidden',)
    list_filter = ('training', 'hidden')

    fieldsets = (
        (None, {
            'fields': (
                'name',
                'training',
                'evaluation_type',
                'sort_order',
                'hidden',
            )
        }),
        SYNC_STATUS_FIELDS,
    )


class ExerciseAdmin(admin.ModelAdmin):
    """Django admin model for the ``Exercise`` model."""

    list_display = ('name', 'evaluation', 'sort_order')
    list_filter = ('evaluation__training', 'evaluation')

    fieldsets = (
        (None, {
            'fields': (
                'name',
                'evaluation',
                'sort_order',
            )
        }),
        SYNC_STATUS_FIELDS,
    )


class CriterionAdmin(admin.ModelAdmin):
    """Django admin model for the ``Criterion`` model."""

    list_display = ('description', 'criterion_type', 'exercise', 'sort_order')
    list_filter = ('exercise__evaluation', 'exercise')

    fieldsets = (
        (None, {
            'fields': (
                'description',
                'criterion_type',
                'exercise',
                'sort_order',
            )
        }),
        SYNC_STATUS_FIELDS,
    )


class RatingAdmin(admin.ModelAdmin):
    """Django admin model for the ``Rating`` model."""

    list_display = (
        'trainee', 'judge', 'score', 'text', 'criterion',
    )
    list_filter = (
        'criterion__exercise',
        'criterion',
    )

    fieldsets = (
        (None, {
            'fields': (
                'criterion',
                'session',
                'trainee',
                'judge',
                'score',
                'text',
            )
        }),
        SYNC_STATUS_FIELDS,
    )
    readonly_fields = ('criterion', 'session', 'trainee', 'judge')


admin.site.register(Evaluation, EvaluationAdmin)
admin.site.register(Exercise, ExerciseAdmin)
admin.site.register(Criterion, CriterionAdmin)
admin.site.register(Rating, RatingAdmin)
