"""
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.compensation_action import RemoveCompensationActionModalForm, \
    EditCompensationActionModalForm, NewCompensationActionModalForm
from compensation.models import Compensation, CompensationAction
from konova.decorators import shared_access_required, default_group_required, login_required_modal
from konova.utils.message_templates import COMPENSATION_ACTION_REMOVED, COMPENSATION_ACTION_EDITED, \
    COMPENSATION_ACTION_ADDED
from konova.views.action import AbstractNewCompensationActionView, AbstractEditCompensationActionView, \
    AbstractRemoveCompensationActionView


class NewCompensationActionView(AbstractNewCompensationActionView):
    model = Compensation
    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 EditCompensationActionView(AbstractEditCompensationActionView):
    model = Compensation
    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 RemoveCompensationActionView(AbstractRemoveCompensationActionView):
    model = Compensation
    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)
