"""
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.http import HttpRequest
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.decorators import method_decorator

from compensation.forms.modals.document import NewEcoAccountDocumentModalForm
from compensation.models import EcoAccount, EcoAccountDocument
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 NewEcoAccountDocumentView(AbstractNewDocumentView):
    model = EcoAccount
    form = NewEcoAccountDocumentModalForm
    redirect_url = "compensation:acc:detail"

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


class GetEcoAccountDocumentView(AbstractGetDocumentView):
    model = EcoAccount
    document_model = EcoAccountDocument

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


class RemoveEcoAccountDocumentView(AbstractRemoveDocumentView):
    model = EcoAccount
    document_model = EcoAccountDocument

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


class EditEcoAccountDocumentView(AbstractEditDocumentView):
    model = EcoAccount
    document_model = EcoAccountDocument
    form = EditDocumentModalForm
    redirect_url = "compensation:acc:detail"

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