"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 15.11.21

"""
from django.db import models

from codelist.models import KonovaCode
from codelist.settings import CODELIST_LAW_ID, CODELIST_PROCESS_TYPE_ID
from konova.models import UuidModel


class Legal(UuidModel):
    """
    Holds intervention legal data such as important dates, laws or responsible handler
    """
    # Refers to "zugelassen am"
    registration_date = models.DateField(null=True, blank=True, help_text="Refers to 'Zugelassen am'")

    # Refers to "Bestandskraft am"
    binding_date = models.DateField(null=True, blank=True, help_text="Refers to 'Bestandskraft am'")

    process_type = models.ForeignKey(
        KonovaCode,
        on_delete=models.SET_NULL,
        null=True,
        related_name="+",
        blank=True,
        limit_choices_to={
            "code_lists__in": [CODELIST_PROCESS_TYPE_ID],
            "is_selectable": True,
            "is_archived": False,
        }
    )
    laws = models.ManyToManyField(
        KonovaCode,
        blank=True,
        limit_choices_to={
            "code_lists__in": [CODELIST_LAW_ID],
            "is_selectable": True,
            "is_archived": False,
        }
    )