"""
Couirier History model
"""

from django.db import models

from core.apps.eggs.models import courier, courier_product, group
from core.http.models import base


class CourierHistory(base.AbstractBaseModel):
    courier_id = models.ForeignKey(
        to=courier.Courier,
        on_delete=models.CASCADE,
        related_name="courier_histories",
    )
    courier_product_id = models.ForeignKey(
        to=courier_product.CourierProduct,
        on_delete=models.SET_NULL,
        related_name="courier_histories",
        null=True,  # Allow NULL values
    )
    group_id = models.ForeignKey(
        to=group.Group,
        on_delete=models.SET_NULL,
        null=True,  # Allow NULL values
    )
    get_eggs = models.IntegerField()
    return_eggs = models.IntegerField(null=True, blank=True)
    broken_eggs = models.IntegerField(null=True, blank=True)
    date = models.DateField(auto_now=True, null=True, blank=True)

    def __str__(self) -> str:
        return f"{self.courier_id}, {self.group_id}"

    class Meta:
        verbose_name = "CourierHistory"
        verbose_name_plural = "CourierHistories"
        db_table = "courier_history"
