# -*- coding: utf-8 -*-
from __future__ import annotations

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

from hotpocket_backend.apps.core.models import Model


class ActiveAccessTokensManager(models.Manager):
    def get_queryset(self) -> models.QuerySet[AccessToken]:
        return super().get_queryset().filter(
            deleted_at__isnull=True,
        )


class AccessToken(Model):
    key = models.CharField(
        blank=False,
        default=None,
        null=False,
        max_length=128,
        db_index=True,
        unique=True,
        editable=False,
    )
    origin = models.CharField(
        blank=False, default=None, null=False, db_index=True,
    )
    meta = models.JSONField(blank=True, default=dict, null=True)

    objects = models.Manager()
    active_objects = ActiveAccessTokensManager()

    class Meta:
        verbose_name = _('Access Token')
        verbose_name_plural = _('Access Tokens')

    def __str__(self) -> str:
        return f'<AccessToken pk={self.pk} account_uuid={self.account_uuid}>'
