"""
Order Items model
"""

import decimal

from django.db import models

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


class OrderItems(base.AbstractBaseModel):
    SALE_TYPE_CHOICES = (
        ("optom", "Optom"),
        ("dona", "Dona"),
    )

    group_id = models.ForeignKey(
        group.Group, on_delete=models.CASCADE, null=True
    )
    count = models.IntegerField()
    discount = models.DecimalField(
        max_digits=10, decimal_places=2, null=True, blank=True
    )
    courier_product_id = models.ForeignKey(
        to=courier_product.CourierProduct,
        on_delete=models.CASCADE,
        null=True,
        blank=True,
    )
    order_id = models.ForeignKey(
        order.Order, on_delete=models.CASCADE, related_name="order_items"
    )
    sale_type = models.CharField(max_length=10, choices=SALE_TYPE_CHOICES)

    def __str__(self):
        return f"Product - {self.group_id}, count - {self.count}"

    class Meta:
        verbose_name = "OrderItem"
        verbose_name_plural = "OrderItems"
        db_table = "order_item"
