from django.db import models
from django.utils.translation import gettext_lazy as _

from establishment.models import Establishment
from utils.models import ImageMixin, ProjectBaseMixin


class Partner(ProjectBaseMixin):
    """Partner model."""

    PARTNER = 0
    SPONSOR = 1
    MODEL_TYPES = (
        (PARTNER, _('Partner')),
        (SPONSOR, _('Sponsor')),
    )

    old_id = models.PositiveIntegerField(_('old id'), blank=True, null=True, default=None)
    name = models.CharField(_('name'), max_length=255, blank=True, null=True)
    url = models.URLField(verbose_name=_('Partner URL'))
    image = models.URLField(verbose_name=_('Partner image URL'), null=True)
    establishment = models.ForeignKey(
        Establishment,
        verbose_name=_('Establishment'),
        related_name='partners',
        on_delete=models.CASCADE,
        blank=True,
        null=True,
    )
    type = models.PositiveSmallIntegerField(choices=MODEL_TYPES, default=PARTNER)
    starting_date = models.DateField(_('starting date'), blank=True, null=True)
    expiry_date = models.DateField(_('expiry date'), blank=True, null=True)
    price_per_month = models.DecimalField(_('price per month'), max_digits=10, decimal_places=2, blank=True, null=True)

    class Meta:
        verbose_name = _('partner')
        verbose_name_plural = _('partners')

    def __str__(self):
        return f'{self.url}'
