# 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, PatchedServiceDetailRequestConnectionType, ServiceStatus


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 Service(BaseModel):
    """
    Serializer for service list view.

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

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

    id: Any = Field(description='Deterministic UUID5 from service...')
    name: str = Field(description="Unique service name (e.g., 'enca...", max_length=200)
    description: str | None = Field(None, description='Service description')
    source_code: str | None = Field(
    None,
    description="Source code identifier (e.g., 'e...",
    max_length=50,
)
    status: ServiceStatus = Field(description='Current service state  * `initia...')
    hostname: str | None = Field(None, description='Host machine name', max_length=255)
    is_online: bool = ...
    is_stale: bool = ...
    last_heartbeat_at: Any | None = Field(None, description='Last heartbeat received')
    registered_at: Any | None = Field(None, description='Last registration timestamp')
    is_enabled: bool | None = Field(None, description='Whether service is enabled')



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



class ServiceRequest(BaseModel):
    """
    Serializer for service list view.

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

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

    name: str = Field(
    description="Unique service name (e.g., 'enca...",
    min_length=1,
    max_length=200,
)
    description: str | None = Field(None, description='Service description')
    source_code: str | None = Field(
    None,
    description="Source code identifier (e.g., 'e...",
    max_length=50,
)
    hostname: str | None = Field(None, description='Host machine name', max_length=255)
    is_enabled: bool | None = Field(None, description='Whether service is enabled')



class ServiceDetail(BaseModel):
    """
    Serializer for service detail view.

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

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

    id: Any = Field(description='Deterministic UUID5 from service...')
    name: str = Field(description="Unique service name (e.g., 'enca...", max_length=200)
    description: str | None = Field(None, description='Service description')
    source_code: str | None = Field(
    None,
    description="Source code identifier (e.g., 'e...",
    max_length=50,
)
    owner: int = Field(description='Service owner')
    owner_name: Any = ...
    status: ServiceStatus = Field(description='Current service state  * `initia...')
    error_message: Any = Field(description='Error message if status is ERROR')
    hostname: Any = Field(description='Host machine name')
    pid: int | None = Field(None, description='Process ID')
    executable_path: Any = Field(description='Full path to Python executable')
    working_directory: Any = Field(description='Service working directory')
    sdk_version: Any = Field(description='SDK version')
    python_version: Any = Field(description='Python version')
    memory_mb: float | None = Field(None, description='Memory usage in MB')
    cpu_percent: float | None = Field(None, description='CPU usage percent')
    uptime_seconds: float | None = Field(None, description='Service uptime in seconds')
    items_processed: int = Field(description='Total items processed')
    errors_count: int = Field(description='Total errors encountered')
    registered_at: Any | None = Field(None, description='Last registration timestamp')
    last_heartbeat_at: Any | None = Field(None, description='Last heartbeat received')
    started_at: Any | None = Field(None, description='When service was started')
    stopped_at: Any | None = Field(None, description='When service was stopped')
    is_enabled: bool | None = Field(None, description='Whether service is enabled')
    auto_restart: bool | None = Field(None, description='Auto-restart on crash or failure')
    heartbeat_timeout_seconds: int | None = Field(
    None,
    description='Seconds before marking as offline',
    ge=0,
    le=2147483647,
)
    connection_type: PatchedServiceDetailRequestConnectionType | None = Field(
    None,
    description='How to control this service (grp...',
)
    has_agent: bool | None = Field(None, description='DEPRECATED: Has CMDOP agent inst...')
    agent_url: str | None = Field(
    None,
    description='DEPRECATED: Agent HTTP URL for c...',
    max_length=200,
)
    cmdop_api_key: str | None = Field(
    None,
    description='DEPRECATED: CMDOP API key for cl...',
    max_length=200,
)
    config: dict[str, Any] | None = Field(None, description='Service configuration')
    metadata: dict[str, Any] | None = Field(None, description='Additional metadata')
    is_online: bool = ...
    is_stale: bool = ...
    is_controllable: bool = ...
    is_local: bool = ...
    created_at: Any = ...
    updated_at: Any = ...



class ServiceDetailRequest(BaseModel):
    """
    Serializer for service detail view.

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

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

    name: str = Field(
    description="Unique service name (e.g., 'enca...",
    min_length=1,
    max_length=200,
)
    description: str | None = Field(None, description='Service description')
    source_code: str | None = Field(
    None,
    description="Source code identifier (e.g., 'e...",
    max_length=50,
)
    is_enabled: bool | None = Field(None, description='Whether service is enabled')
    auto_restart: bool | None = Field(None, description='Auto-restart on crash or failure')
    heartbeat_timeout_seconds: int | None = Field(
    None,
    description='Seconds before marking as offline',
    ge=0,
    le=2147483647,
)
    connection_type: PatchedServiceDetailRequestConnectionType | None = Field(
    None,
    description='How to control this service (grp...',
)
    has_agent: bool | None = Field(None, description='DEPRECATED: Has CMDOP agent inst...')
    agent_url: str | None = Field(
    None,
    description='DEPRECATED: Agent HTTP URL for c...',
    max_length=200,
)
    cmdop_api_key: str | None = Field(
    None,
    description='DEPRECATED: CMDOP API key for cl...',
    max_length=200,
)
    config: dict[str, Any] | None = Field(None, description='Service configuration')
    metadata: dict[str, Any] | None = Field(None, description='Additional metadata')



class PatchedServiceDetailRequest(BaseModel):
    """
    Serializer for service detail view.

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

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

    name: str | None = Field(
    None,
    description="Unique service name (e.g., 'enca...",
    min_length=1,
    max_length=200,
)
    description: str | None = Field(None, description='Service description')
    source_code: str | None = Field(
    None,
    description="Source code identifier (e.g., 'e...",
    max_length=50,
)
    is_enabled: bool | None = Field(None, description='Whether service is enabled')
    auto_restart: bool | None = Field(None, description='Auto-restart on crash or failure')
    heartbeat_timeout_seconds: int | None = Field(
    None,
    description='Seconds before marking as offline',
    ge=0,
    le=2147483647,
)
    connection_type: PatchedServiceDetailRequestConnectionType | None = Field(
    None,
    description='How to control this service (grp...',
)
    has_agent: bool | None = Field(None, description='DEPRECATED: Has CMDOP agent inst...')
    agent_url: str | None = Field(
    None,
    description='DEPRECATED: Agent HTTP URL for c...',
    max_length=200,
)
    cmdop_api_key: str | None = Field(
    None,
    description='DEPRECATED: CMDOP API key for cl...',
    max_length=200,
)
    config: dict[str, Any] | None = Field(None, description='Service configuration')
    metadata: dict[str, Any] | None = Field(None, description='Additional metadata')



