import logging

from django.core.exceptions import ValidationError
from django.db import models

from django.utils.translation import gettext_lazy as _
from model_utils.models import TimeStampedModel, TimeFramedModel


logger = logging.getLogger(__name__)


class Bar(TimeStampedModel):
    name = models.CharField(max_length=100, blank=False, null=False, unique=True, verbose_name=_('Name'))

    class Meta:
        verbose_name = _('Bar')
        verbose_name_plural = _('Bars')

    def __str__(self):
        return self.name


class Item(TimeStampedModel):
    identifier = models.CharField(max_length=100, blank=True, null=True, unique=True, verbose_name=_('Identifier'))
    name = models.CharField(max_length=100, blank=False, null=False, verbose_name=_('Name'))
    price = models.DecimalField(max_digits=10, decimal_places=2, blank=False, null=False, verbose_name=_('Price'))
    quantity = models.PositiveIntegerField(blank=False, null=False, default=0, verbose_name=_('Quantity'))

    class Meta:
        verbose_name = _('Item')
        verbose_name_plural = _('Items')

    def __str__(self):
        return self.name


class BarRecord(TimeStampedModel):
    bar = models.ForeignKey(Bar, on_delete=models.CASCADE, related_name='records', verbose_name=_('Bar'))
    item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='records', verbose_name=_('Item'))
    quantity = models.PositiveIntegerField(blank=False, null=False, default=0, verbose_name=_('Quantity'))

    class Meta:
        verbose_name = _('Bar Record')
        verbose_name_plural = _('Bar Records')

    def __str__(self):
        return f'{self.bar} - {self.item}'