# Auto-generated by DjangoCFG - see CLAUDE.md

from __future__ import annotations
import datetime
from typing import Any

from pydantic import BaseModel, ConfigDict, Field

from ..enums import OAuthConnectionProvider


class OAuthConnection(BaseModel):
    """
    Serializer for OAuth connection info (user-facing).

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    id: int = ...
    provider: OAuthConnectionProvider = Field(description='OAuth provider name (github, goo...')
    provider_display: Any = ...
    provider_username: Any = Field(description='Username on the OAuth provider p...')
    provider_email: str = Field(description='Email from OAuth provider (may d...')
    provider_avatar_url: str = Field(description='Avatar URL from OAuth provider')
    connected_at: datetime.datetime = Field(description='When this OAuth connection was c...')
    last_login_at: datetime.datetime = Field(description='Last time this OAuth connection ...')



class OAuthDisconnectRequestRequest(BaseModel):
    """
    Request to disconnect OAuth provider.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    provider: OAuthConnectionProvider = Field(description='OAuth provider to disconnect  * ...')



class OAuthError(BaseModel):
    """
    Error response for OAuth endpoints.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    error: str = Field(description='Error code')
    error_description: str | None = Field(None, description='Human-readable error description')



class OAuthAuthorizeRequestRequest(BaseModel):
    """
    Request to start OAuth flow.

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    redirect_uri: str | None = Field(None, description='URL to redirect after OAuth auth...')
    source_url: str | None = Field(None, description='Optional source URL for registra...')



class OAuthAuthorizeResponse(BaseModel):
    """
    Response with OAuth authorization URL.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    authorization_url: str = Field(description='Full URL to redirect user to OAu...')
    state: str = Field(description='State token for CSRF protection....')



class OAuthCallbackRequestRequest(BaseModel):
    """
    Request to complete OAuth flow (callback handler).

    Request model (no read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    code: str = Field(
    description='Authorization code from OAuth pr...',
    min_length=10,
    max_length=500,
)
    state: str = Field(
    description='State token for CSRF verificatio...',
    min_length=20,
    max_length=100,
)
    redirect_uri: str | None = Field(None, description='Same redirect_uri used in author...')



class OAuthTokenResponse(BaseModel):
    """
    Response with JWT tokens after OAuth authentication. When 2FA is required: -
    requires_2fa: True - session_id: UUID of 2FA verification session -
    access/refresh/user: null When 2FA is not required: - requires_2fa: False -
    session_id: null - access/refresh/user: populated

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    requires_2fa: bool | None = Field(None, description='True if 2FA verification is requ...')
    session_id: str | None = Field(None, description='2FA session ID (only when requir...')
    access: str | None = Field(None, description='JWT access token (null when requ...')
    refresh: str | None = Field(None, description='JWT refresh token (null when req...')
    user: dict[str, Any] | None = Field(None, description='Authenticated user info (null wh...')
    is_new_user: bool = Field(description='True if a new user was created d...')
    is_new_connection: bool = Field(description='True if a new OAuth connection w...')
    should_prompt_2fa: bool | None = Field(None, description='True if user should be prompted ...')



class OAuthProvidersResponse(BaseModel):
    """
    Response with available OAuth providers.

    Response model (includes read-only fields).
    """

    model_config = ConfigDict(
        validate_assignment=True,
        extra="allow",
        frozen=False,
    )

    providers: list[dict[str, Any]] = Field(description='List of available OAuth providers')



