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


class WebAuthDevice(models.Model):
    """
    Identifies a single key-pair provisioned on a user's authenticator for
    authenticating against only this site.
    """

    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name="webauth_devices",
    )
    name = models.CharField(
        max_length=250,
        help_text=_("nickname to help the user identify a given key"),
    )
    credential_id = models.BinaryField(max_length=128)
    public_key = models.BinaryField(max_length=256)
    format = models.CharField(
        max_length=250,
        help_text=_("generated by the client authenticator to identify this key")
    )
    type = models.CharField(max_length=250)
    sign_count = models.PositiveIntegerField()
    created_at = models.DateTimeField(auto_now_add=True)
