from django.db import models
from BaseModels.base_models import BaseModel
from django.utils.translation import gettext_lazy as _
from colorfield.fields import ColorField

class SubscribeOption(BaseModel):

    class Meta:
        verbose_name = _('Опция подписки')
        verbose_name_plural = _('Опции подписки')
        ordering = ['order']



class Subscribe(BaseModel):

    price = models.FloatField(verbose_name='Стоимость', default=0)
    options = models.ManyToManyField(
        SubscribeOption, verbose_name=_('Подключенные опции'), blank=True, related_name='rel_subscribes_for_option'
    )
    period_name = models.CharField(max_length=250, verbose_name=_('Название периода'))
    period = models.IntegerField(default=0, verbose_name=_('Длительность подписки в часах'))

    bg_color = ColorField(default='#FFFFFF', verbose_name=_('Цвет фона'))
    text_color = ColorField(default='#000000', verbose_name=_('Цвет текста'))

    class Meta:
        verbose_name = _('Подписка')
        verbose_name_plural = _('Подписки')


class SubscribeForUser(BaseModel):
    from AuthApp.models import User

    user = models.ForeignKey(
        User, verbose_name=_('Пользователь'), related_name='rel_userSubscribes_for_user', on_delete=models.CASCADE)
    subscribe = models.ForeignKey(
        Subscribe, verbose_name=_('Подписка'), null=True, blank=True, related_name='rel_userSubscribes_for_subscribe',
        on_delete=models.SET_NULL
    )
    last_paid_DT = models.DateTimeField(verbose_name=_('Последняя дата оплаты'), blank=True, null=True)
    paid_period_from_DT = models.DateTimeField(verbose_name=_('Оплаченный период с'), blank=True, null=True)
    paid_period_to_DT = models.DateTimeField(verbose_name=_('Оплаченный период до'), blank=True, null=True)

    auto_continue = models.BooleanField(default=False, verbose_name=_('Автопродление'))

    receive_finish_subscribe_msg = models.BooleanField(
        default=False, verbose_name=_('Получать сообщения о окончании периода'))

    class Meta:
        verbose_name = _('Пользовательская подписка')
        verbose_name_plural = _('Пользовательские подписки')