"""Redis-backed WebAuthn challenge store."""
from __future__ import annotations
from typing import Optional
from uuid import uuid4

from redis import asyncio as aioredis


class RedisChallengeStore:
    """Store WebAuthn challenges in Redis with TTL."""

    def __init__(self, redis: aioredis.Redis):
        self._redis = redis

    async def set(self, key: str, value: str, ttl_seconds: int = 300) -> None:
        await self._redis.setex(key, ttl_seconds, value)

    async def get(self, key: str) -> Optional[str]:
        return await self._redis.get(key)

    async def delete(self, key: str) -> None:
        await self._redis.delete(key)


def create_state_id() -> str:
    """Create a unique state ID for WebAuthn flow."""
    return str(uuid4())
