from django.db import models
from minecraft_manager.api.api import generate_password


class TokenManager(models.Manager):
    def get_queryset(self):
        return super(TokenManager, self).get_queryset().none()


class Token(models.Model):
    key = models.CharField("Key", default=generate_password, max_length=50, unique=True)
    description = models.CharField("Description", max_length=200, blank=True)
    active = models.BooleanField("Active", default=True)
    web_get_permission = models.BooleanField("Web GET", default=False)
    web_post_permission = models.BooleanField("Web POST", default=False)
    plugin_get_permission = models.BooleanField("Plugin GET", default=False)
    plugin_post_permission = models.BooleanField("Plugin POST", default=False)
    form_get_permission = models.BooleanField("Form GET", default=False)
    form_post_permission = models.BooleanField("Form POST", default=False)
    model_get_permission = models.BooleanField("Model GET", default=False)
    model_post_permission = models.BooleanField("Model POST", default=False)
    stats_get_permission = models.BooleanField("Stats GET", default=False)
    stats_post_permission = models.BooleanField("Stats POST", default=False)
    objects = models.Manager()
    api = TokenManager()

    @property
    def display(self):
        return self.description if self.description else self.key

    def __str__(self):
        return self.key
