from __future__ import annotations

from datetime import datetime
from uuid import UUID

from pydantic import BaseModel, ConfigDict, Field


# ── Request schemas ──────────────────────────────────────────────


class ChallengeRequest(BaseModel):
    """Request a challenge nonce for Ed25519 authentication."""

    address: str = Field(..., min_length=1, max_length=64, description="Duniter V2 SS58 address")


class VerifyRequest(BaseModel):
    """Submit the signed challenge to obtain a session token."""

    address: str = Field(..., min_length=1, max_length=64)
    signature: str = Field(..., description="Ed25519 signature of the challenge (hex)")
    challenge: str = Field(..., description="The challenge string that was signed")


# ── Response schemas ─────────────────────────────────────────────


class ChallengeResponse(BaseModel):
    """Returned after requesting a challenge."""

    challenge: str
    expires_at: datetime


class IdentityOut(BaseModel):
    """Public representation of a Duniter identity."""

    model_config = ConfigDict(from_attributes=True)

    id: UUID
    address: str
    display_name: str | None = None
    wot_status: str
    is_smith: bool
    is_techcomm: bool


class TokenResponse(BaseModel):
    """Returned after successful challenge verification."""

    token: str
    identity: IdentityOut
