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

"""
from dal import autocomplete
from django import forms
from django.utils.translation import gettext_lazy as _

from codelist.models import KonovaCode
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_HANDLER_ID


class CompensationResponsibleFormMixin(forms.Form):
    """ Encapsulates form fields used in different compensation related models like EcoAccount or EMA

    """
    conservation_office = forms.ModelChoiceField(
        label=_("Conservation office"),
        label_suffix="",
        help_text=_("Select the responsible office"),
        queryset=KonovaCode.objects.filter(
            is_archived=False,
            is_leaf=True,
            code_lists__in=[CODELIST_CONSERVATION_OFFICE_ID],
        ),
        widget=autocomplete.ModelSelect2(
            url="codelist:conservation-office-autocomplete",
            attrs={
                "data-placeholder": _("Click for selection")
            }
        ),
    )
    conservation_file_number = forms.CharField(
        label=_("Conservation office file number"),
        label_suffix="",
        max_length=255,
        required=False,
        widget=forms.TextInput(
            attrs={
                "placeholder": _("ETS-123/ABC.456"),
                "class": "form-control",
            }
        )
    )

    handler_type = forms.ModelChoiceField(
        label=_("Eco-Account handler type"),
        label_suffix="",
        help_text=_("What type of handler is responsible for the ecoaccount?"),
        required=False,
        queryset=KonovaCode.objects.filter(
            is_archived=False,
            is_leaf=True,
            code_lists__in=[CODELIST_HANDLER_ID],
        ),
        widget=autocomplete.ModelSelect2(
            url="codelist:handler-autocomplete",
            attrs={
                "data-placeholder": _("Click for selection"),
            }
        ),
    )
    handler_detail = forms.CharField(
        label=_("Eco-Account handler detail"),
        label_suffix="",
        max_length=255,
        required=False,
        help_text=_("Detail input on the handler"),
        widget=forms.TextInput(
            attrs={
                "placeholder": _("Company Mustermann"),
                "class": "form-control",
            }
        )
    )


class CEFCompensationFormMixin(forms.Form):
    """ A form mixin, providing CEF compensation field

    """
    is_cef = forms.BooleanField(
        label_suffix="",
        label=_("Is CEF"),
        help_text=_("Optionally: Whether this compensation is a CEF compensation?"),
        required=False,
        widget=forms.CheckboxInput()
    )


class CoherenceCompensationFormMixin(forms.Form):
    """ A form mixin, providing coherence compensation field

    """
    is_coherence_keeping = forms.BooleanField(
        label_suffix="",
        label=_("Is coherence keeping"),
        help_text=_("Optionally: Whether this compensation is a coherence keeping compensation?"),
        required=False,
        widget=forms.CheckboxInput()
    )


class PikCompensationFormMixin(forms.Form):
    """ A form mixin, providing PIK compensation field

    """
    is_pik = forms.BooleanField(
        label_suffix="",
        label=_("Is PIK"),
        help_text=_("Optionally: Whether this compensation is a compensation integrated in production?"),
        required=False,
        widget=forms.CheckboxInput()
    )