"""
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 compensation.forms.modals.document import NewCompensationDocumentModalForm
from compensation.models import Compensation, CompensationDocument
from konova.decorators import shared_access_required, default_group_required, login_required_modal
from konova.forms.modals import EditDocumentModalForm
from konova.views.document import AbstractNewDocumentView, AbstractGetDocumentView, AbstractRemoveDocumentView, \
    AbstractEditDocumentView


class NewCompensationDocumentView(AbstractNewDocumentView):
    model = Compensation
    form = NewCompensationDocumentModalForm
    redirect_url = "compensation:detail"

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


class GetCompensationDocumentView(AbstractGetDocumentView):
    model = Compensation
    document_model = CompensationDocument

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


class RemoveCompensationDocumentView(AbstractRemoveDocumentView):
    model = Compensation
    document_model = CompensationDocument

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


class EditCompensationDocumentView(AbstractEditDocumentView):
    model = Compensation
    document_model = CompensationDocument
    form = EditDocumentModalForm
    redirect_url = "compensation:detail"

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