"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22

"""
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator

from intervention.forms.modals.document import NewInterventionDocumentModalForm
from intervention.models import Intervention, InterventionDocument
from konova.decorators import default_group_required, shared_access_required
from konova.forms.modals import EditDocumentModalForm
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
    AbstractEditDocumentView


class NewInterventionDocumentView(AbstractNewDocumentView):
    model = Intervention
    form = NewInterventionDocumentModalForm
    redirect_url = "intervention:detail"

    @method_decorator(login_required)
    @method_decorator(default_group_required)
    @method_decorator(shared_access_required(Intervention, "id"))
    def dispatch(self, request, *args, **kwargs):
        return super().dispatch(request, *args, **kwargs)


class GetInterventionDocumentView(AbstractGetDocumentView):
    model = Intervention
    document_model = InterventionDocument

    @method_decorator(login_required)
    @method_decorator(default_group_required)
    @method_decorator(shared_access_required(Intervention, "id"))
    def dispatch(self, request, *args, **kwargs):
        return super().dispatch(request, *args, **kwargs)


class RemoveInterventionDocumentView(AbstractRemoveDocumentView):
    model = Intervention
    document_model = InterventionDocument

    @method_decorator(login_required)
    @method_decorator(default_group_required)
    @method_decorator(shared_access_required(Intervention, "id"))
    def dispatch(self, request, *args, **kwargs):
        return super().dispatch(request, *args, **kwargs)


class EditInterventionDocumentView(AbstractEditDocumentView):
    model = Intervention
    document_model = InterventionDocument
    form = EditDocumentModalForm
    redirect_url = "intervention:detail"

    @method_decorator(login_required)
    @method_decorator(default_group_required)
    @method_decorator(shared_access_required(Intervention, "id"))
    def dispatch(self, request, *args, **kwargs):
        return super().dispatch(request, *args, **kwargs)
