from django.contrib import admin

from intervention.models import Intervention, Responsibility, Legal, Revocation, InterventionDocument
from konova.admin import AbstractDocumentAdmin, BaseObjectAdmin


class InterventionAdmin(BaseObjectAdmin):
    list_display = [
        "id",
        "identifier",
        "title",
        "created",
        "deleted",
    ]

    filter_horizontal = [
        "users",
        "teams",
    ]

    def get_fields(self, request, obj=None):
        return super().get_fields(request, obj) + [
            "identifier",
            "title",
            "comment",
            "checked",
            "recorded",
            "users",
            "teams",
            "geometry",
        ]

    def get_readonly_fields(self, request, obj=None):
        return super().get_readonly_fields(request, obj) + [
            "checked",
            "recorded",
            "geometry",
        ]


class InterventionDocumentAdmin(AbstractDocumentAdmin):
    pass


class ResponsibilityAdmin(admin.ModelAdmin):
    list_display = [
        "id",
        "registration_office",
        "registration_file_number",
        "conservation_office",
        "conservation_file_number",
        "handler",
    ]


class LegalAdmin(admin.ModelAdmin):
    list_display = [
        "id",
        "process_type",
        "registration_date",
        "binding_date",
    ]


class RevocationAdmin(admin.ModelAdmin):
    list_display = [
        "id",
        "date",
        "comment",
        "created",
    ]


admin.site.register(Intervention, InterventionAdmin)

# Outcommented for a cleaner admin backend on production
#admin.site.register(Responsibility, ResponsibilityAdmin)
#admin.site.register(Legal, LegalAdmin)
#admin.site.register(Revocation, RevocationAdmin)
#admin.site.register(InterventionDocument, InterventionDocumentAdmin)
