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

class QuestionCategory(BaseModel):
    parent_category = models.ForeignKey(
        'QuestionCategory', verbose_name=_('Родительская категория'), related_name='categories_for_parentCategory',
        on_delete=models.CASCADE, null=True, blank=True
    )
    parsed = models.BooleanField(verbose_name='Использован', default=False)

    def __str__(self):
        if self.name:
            return f'{self.name}'
        else:
            return str(self.id)


    class Meta:
        verbose_name = _('Категория вопроса')
        verbose_name_plural = _('Категории вопросов')


class Question(BaseModel):

    category = models.ForeignKey(
        QuestionCategory, verbose_name='Категория', related_name='rel_questions_for_category',
        on_delete=models.SET_NULL, null=True

    )

    game_level = models.IntegerField(verbose_name=_('Уровень игры'), default=1)
    time_for_answer = models.IntegerField(verbose_name=_('Время на ответ (сек)'), default=7)
    used_count = models.IntegerField(verbose_name=_('Количество использования'), default=0)
    comment = models.TextField(verbose_name=_('Комментарий'), null=True, blank=True)

    def __str__(self):
        if self.name:
            return f'{self.name}'
        else:
            return str(self.id)


    class Meta:
        permissions = (

        )

        verbose_name = _('Вопрос')
        verbose_name_plural = _('Вопросы')
        # ordering = ('user__last_name', 'user__first_name')


class Answer(BaseModel):
    question = models.ForeignKey(
        Question, verbose_name=_('Вопрос'), related_name='rel_answers_for_question', on_delete=models.CASCADE)
    right_answer = models.BooleanField(verbose_name=_('Правильный'), default=False)
    comment = models.TextField(verbose_name=_('Комментарий'), null=True, blank=True)

    def __str__(self):
        if self.name:
            return f'{self.name}'
        else:
            return str(self.id)


    class Meta:
        verbose_name = _('Ответ')
        verbose_name_plural = _('Ответы')
        ordering = ('question',)