# Auto-generated by DjangoCFG - see CLAUDE.md

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict, Field

from ..enums import ApiKeyKeyType


class ApiKey(BaseModel):
    """
    Serializer for reading API keys (without exposing full key).

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

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

    id: Any = ...
    name: Any = Field(description='Key name for identification')
    owner: int = Field(description='Key owner')
    owner_name: Any = ...
    key_prefix: Any = Field(description='Key prefix (pk_, sk_, dk_)')
    key_hint: Any = Field(description='Last 4 characters of key')
    display_key: Any = ...
    key_type: ApiKeyKeyType = Field(description='Key type/environment  * `product...')
    is_global: bool = Field(description="Access all owner's services")
    can_register: bool = Field(description='Can register new services')
    can_control: bool = Field(description='Can send control commands')
    can_view_logs: bool = Field(description='Can view service logs')
    is_active: bool = Field(description='Whether key is active')
    is_expired: bool = ...
    is_valid: bool = ...
    expires_at: Any | None = Field(None, description='Key expiration (null = never)')
    last_used_at: Any | None = Field(None, description='Last usage timestamp')
    usage_count: int = Field(description='Total usage count')
    services_count: int = ...
    created_at: Any = ...
    updated_at: Any = ...



class PaginatedApiKeyList(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[ApiKey] = Field(description='Array of items for current page')



class ApiKeyCreateRequest(BaseModel):
    """
    Serializer for creating new API key.

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

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

    name: str = Field(min_length=1, max_length=100)
    key_type: ApiKeyKeyType | None = Field(None, description='* `production` - Production * `s...')
    is_global: bool | None = None
    can_register: bool | None = None
    can_control: bool | None = None
    can_view_logs: bool | None = None
    expires_in_days: int | None = Field(None, description='Days until key expires', ge=1, le=365)
    service_ids: list[str] | None = Field(None, description='List of service IDs this key can...')



class ApiKeyCreateResponse(BaseModel):
    """
    Response for API key creation (includes full key ONCE).

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

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

    id: str = ...
    name: str = ...
    key: str = Field(description='Full API key - save this, it won...')
    key_type: str = ...
    expires_at: str | None = None
    created_at: str = ...



class PatchedApiKeyUpdateRequest(BaseModel):
    """
    Serializer for updating API key.

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

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

    name: str | None = Field(None, min_length=1, max_length=100)
    is_active: bool | None = None
    is_global: bool | None = None
    can_register: bool | None = None
    can_control: bool | None = None
    can_view_logs: bool | None = None
    service_ids: list[str] | None = Field(None, description='List of service IDs this key can...')



