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

"""
from django.core.validators import MinValueValidator
from django.db import models

from intervention.models import Intervention
from konova.models import BaseResource


class Payment(BaseResource):
    """
    Holds data on a payment for an intervention (alternative to a classic compensation)
    """
    amount = models.FloatField(validators=[MinValueValidator(limit_value=0.00)])
    due_on = models.DateField(null=True, blank=True)
    comment = models.TextField(
        null=True,
        blank=True,
        help_text="Refers to german money transfer 'Verwendungszweck'",
    )
    intervention = models.ForeignKey(
        Intervention,
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        related_name='payments'
    )

    class Meta:
        ordering = [
            "-amount",
        ]