# 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 (
    DeviceAuthorizeRequestAction,
    TokenErrorError,
    TokenRequestRequestGrantType,
    TokenRevokeRequestTokenTypeHint,
)


class DeviceCodeRequestRequest(BaseModel):
    """
    Request body for POST /api/oauth/device Client sends metadata about itself.

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

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

    client_name: str | None = Field(
    None,
    description='Client application name',
    min_length=1,
    max_length=100,
)
    client_version: str | None = Field(
    None,
    description='Client version (e.g., 1.0.0)',
    max_length=100,
)
    client_hostname: str | None = Field(
    None,
    description='Client machine hostname',
    max_length=255,
)
    client_platform: str | None = Field(
    None,
    description='OS platform: darwin, linux, windows',
    max_length=100,
)



class DeviceCodeResponse(BaseModel):
    """
    Response body for POST /api/oauth/device Returns device code info for CLI to
    display to user.

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

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

    device_code: str = Field(description='Device code for polling (not sho...')
    user_code: str = Field(description='Human-readable code to show user...')
    verification_uri: str = Field(description='URL where user authorizes (e.g.,...')
    expires_in: int = Field(description='Seconds until device code expire...')
    interval: int = Field(description='Polling interval in seconds (typ...')



class TokenRequestRequest(BaseModel):
    """
    Request body for POST /api/oauth/token CLI polls with device_code until
    approved.

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

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

    grant_type: TokenRequestRequestGrantType = Field(
    description='OAuth grant type  * `urn:ietf:pa...',
)
    device_code: str | None = Field(
    None,
    description='Device code from initial request...',
    min_length=1,
)
    refresh_token: str | None = Field(
    None,
    description='Refresh token (for token refresh)',
    min_length=1,
)



class TokenList(BaseModel):
    """
    Serializer for listing user's CLI tokens.

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

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

    id: str = ...
    access_token_prefix: str = Field(
    description='First 12 characters for identifi...',
    max_length=12,
)
    workspace_name: str = ...
    client_name: str | None = Field(None, max_length=100)
    client_hostname: str | None = Field(None, max_length=255)
    client_platform: str | None = Field(
    None,
    description='OS platform: darwin, linux, windows',
    max_length=100,
)
    created_at: datetime.datetime = ...
    last_used_at: datetime.datetime | None = Field(
    None,
    description='Last time access token was used',
)
    revoked_at: datetime.datetime | None = None
    is_active: Any = ...



class PaginatedTokenListList(BaseModel):
    """
    
    Response model (includes read-only fields).
    """

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

    count: int = Field(description='Total number of items across all...')
    page: int = Field(description='Current page number (1-based)')
    pages: int = Field(description='Total number of pages')
    page_size: int = Field(description='Number of items per page')
    has_next: bool = Field(description='Whether there is a next page')
    has_previous: bool = Field(description='Whether there is a previous page')
    next_page: int | None = Field(None, description='Next page number (null if no nex...')
    previous_page: int | None = Field(None, description='Previous page number (null if no...')
    results: list[TokenList] = Field(description='Array of items for current page')



class TokenResponse(BaseModel):
    """
    Response body for POST /api/oauth/token Returns access token and refresh
    token.

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

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

    access_token: str = Field(description='Access token (cmdop_...)')
    refresh_token: str = Field(description='Refresh token (clitr_...)')
    token_type: str | None = Field(None, description='Token type (always Bearer)')
    expires_in: int = Field(description='Access token expiry in seconds')
    scope: str | None = Field(None, description='Token scope')
    workspace_id: str = Field(description='Workspace ID')
    workspace_name: str = Field(description='Workspace name')
    user_id: str = Field(description='User ID')
    user_email: str | None = Field(None, description='User email (optional)')



class TokenInfo(BaseModel):
    """
    Response for GET /api/oauth/token/info Returns information about current
    token.

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

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

    id: str = ...
    access_token_prefix: str = Field(
    description='First 12 characters for identifi...',
    max_length=12,
)
    workspace_id: str = ...
    workspace_name: str = ...
    user_id: str = ...
    username: str = ...
    client_name: str | None = Field(None, max_length=100)
    client_version: str | None = Field(None, max_length=100)
    client_hostname: str | None = Field(None, max_length=255)
    client_platform: str | None = Field(
    None,
    description='OS platform: darwin, linux, windows',
    max_length=100,
)
    created_at: datetime.datetime = ...
    access_token_expires_at: datetime.datetime = ...
    refresh_token_expires_at: datetime.datetime = ...
    last_used_at: datetime.datetime | None = Field(
    None,
    description='Last time access token was used',
)
    is_expired: Any = ...
    is_refresh_expired: Any = ...



class TokenRevokeRequest(BaseModel):
    """
    Request body for POST /api/oauth/revoke Revoke access token or refresh
    token.

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

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

    token: str = Field(description='Token to revoke (access or refresh)', min_length=1)
    token_type_hint: TokenRevokeRequestTokenTypeHint | None = Field(
    None,
    description='Hint about token type (optional)...',
)



class DeviceAuthorizeResponse(BaseModel):
    """
    Response for device authorization.

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

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

    success: bool = ...
    message: str = ...
    user_code: str = ...
    status: str = ...



class TokenError(BaseModel):
    """
    Error response for POST /api/oauth/token OAuth 2.0 standard error format.

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

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

    error: TokenErrorError = Field(description='OAuth error code  * `authorizati...')
    error_description: str | None = Field(None, description='Human-readable error description')



class DeviceAuthorizeRequest(BaseModel):
    """
    Request body for POST /api/oauth/authorize User approves or denies device
    code in browser.

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

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

    user_code: str = Field(
    description='User code to authorize (e.g., AB...',
    min_length=1,
    max_length=10,
)
    action: DeviceAuthorizeRequestAction = Field(description='User decision: approve or deny  ...')
    workspace_id: str | None = Field(None, description='Workspace ID to grant access to ...')



