# Auto-generated by DjangoCFG - see CLAUDE.md

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict, Field

from ..enums import (
    CommandAckRequestStatus,
    LogEntryRequestLevel,
    PatchedServiceDetailRequestConnectionType,
    ServiceStatus,
)


class CommandAckRequest(BaseModel):
    """
    Serializer for command acknowledgment from SDK.

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

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

    command_id: str = ...
    status: CommandAckRequestStatus = Field(description='* `acknowledged` - Acknowledged ...')
    result: dict[str, Any] | None = None
    error: str | None = None
    executed_at: str | None = None



class CommandAckResponse(BaseModel):
    """
    Response for command acknowledgment.

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

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

    success: bool = ...
    command_id: str = ...
    status: str = ...



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 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 ServiceHeartbeatRequest(BaseModel):
    """
    Serializer for service heartbeat from SDK.

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

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

    service_id: str | None = Field(None, description='Service UUID')
    status: ServiceStatus | None = Field(None, description='Current service status  * `initi...')
    memory_mb: float | None = None
    cpu_percent: float | None = None
    uptime_seconds: float | None = None
    items_processed: int | None = None
    errors_count: int | None = None
    extra_data: dict[str, Any] | None = None



class ServiceHeartbeatResponse(BaseModel):
    """
    Response for service heartbeat.

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

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

    received: bool = ...
    server_time: str = ...
    commands_pending: int = ...



class LogEntryRequest(BaseModel):
    """
    Serializer for single log entry in batch.

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

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

    level: LogEntryRequestLevel = Field(description='* `debug` - Debug * `info` - Inf...')
    message: str = Field(min_length=1)
    timestamp: str = ...
    extra: dict[str, Any] | None = None
    exception_type: str | None = None
    exception_message: str | None = None
    traceback: str | None = None
    function: str | None = None
    module: str | None = None
    line_number: int | None = None



class LogBatchRequest(BaseModel):
    """
    Serializer for log batch from SDK.

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

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

    service_id: str | None = Field(None, description='Service UUID')
    batch_id: str = Field(description='Batch ID for deduplication', min_length=1, max_length=100)
    entries: list[LogEntryRequest] = Field(description='Log entries')
    run_id: str | None = Field(None, description='Run correlation ID', max_length=100)
    created_at: str | None = None



class LogBatchResponse(BaseModel):
    """
    Response for log batch submission.

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

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

    accepted: int = ...
    rejected: int = ...
    batch_id: str = ...



class ServiceRegistrationRequest(BaseModel):
    """
    Serializer for service registration from SDK.

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

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

    service_id: str | None = Field(None, description='Service UUID (auto-generated if ...')
    name: str = Field(description='Unique service name', min_length=1, max_length=200)
    description: str | None = None
    source_code: str | None = Field(None, max_length=50)
    hostname: str = Field(min_length=1, max_length=255)
    pid: int = ...
    executable_path: str | None = Field(None, min_length=1, max_length=1000)
    working_directory: str | None = Field(None, min_length=1, max_length=1000)
    sdk_version: str | None = Field(None, min_length=1, max_length=20)
    python_version: str | None = Field(None, min_length=1, max_length=50)
    connection_type: PatchedServiceDetailRequestConnectionType | None = Field(
    None,
    description='How to control this service (loc...',
)
    config: dict[str, Any] | None = None
    metadata: dict[str, Any] | None = None



class ServiceRegistrationResponse(BaseModel):
    """
    Response for service registration.

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

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

    success: bool = ...
    service_id: str = ...
    message: str = ...
    server_time: str = ...
    config: dict[str, Any] | None = None



