# Auto-generated by DjangoCFG - see CLAUDE.md

from __future__ import annotations
import datetime
from typing import Any

from pydantic import BaseModel, ConfigDict, Field


class GRPCHealthCheck(BaseModel):
    """
    gRPC health check response.

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

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

    status: str = Field(description='Health status: healthy or unhealthy')
    server_host: str = Field(description='Configured gRPC server host')
    server_port: int = Field(description='Configured gRPC server port')
    enabled: bool = Field(description='Whether gRPC is enabled')
    timestamp: str = Field(description='Current timestamp')



class GRPCServiceRegistryMethodStats(BaseModel):
    """
    Statistics for a single method.

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

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

    total_requests: int | None = Field(None, description='Total requests')
    successful: int | None = Field(None, description='Successful requests')
    errors: int | None = Field(None, description='Failed requests')
    success_rate: float | None = Field(None, description='Success rate percentage')
    avg_duration_ms: float | None = Field(None, description='Average duration in milliseconds')
    p50_duration_ms: float | None = Field(None, description='P50 duration in milliseconds')
    p95_duration_ms: float | None = Field(None, description='P95 duration in milliseconds')
    p99_duration_ms: float | None = Field(None, description='P99 duration in milliseconds')



class MethodSummary(BaseModel):
    """
    Summary information for a method.

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

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

    name: str = Field(description='Method name')
    full_name: str = Field(description='Full method path')
    service_name: str = Field(description='Service name')
    request_type: str | None = Field(None, description='Request message type')
    response_type: str | None = Field(None, description='Response message type')
    stats: GRPCServiceRegistryMethodStats = ...



class MethodList(BaseModel):
    """
    List of methods response (for monitoring endpoint).

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

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

    methods: list[MethodSummary] | None = Field(None, description='List of methods')
    total_methods: int = Field(description='Total number of methods')



class GRPCRegisteredService(BaseModel):
    """
    Information about a registered gRPC service.

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

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

    name: str = Field(description='Service name')
    full_name: str = Field(description='Full service name with package')
    methods_count: int = Field(description='Number of methods in service')
    request_count: int = Field(description='Total requests to this service i...')
    error_count: int = Field(description='Error requests to this service i...')
    success_rate: float = Field(description='Success rate percentage for this...')



class GRPCServerStatus(BaseModel):
    """
    gRPC server status and information for overview stats.

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

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

    status: str = Field(description='Server status (running, stopped,...')
    is_running: bool = Field(description='Whether server is currently running')
    host: str = Field(description='Server host address')
    port: int = Field(description='Server port')
    address: str = Field(description='Full server address (host:port)')
    pid: int | None = Field(None, description='Process ID')
    hostname: str = Field(description='Server hostname')
    started_at: datetime.datetime | None = Field(None, description='Server start time')
    uptime_seconds: int = Field(description='Server uptime in seconds')
    last_heartbeat: datetime.datetime | None = Field(None, description='Last heartbeat timestamp')
    services: list[GRPCRegisteredService] = Field(
    description='List of registered services with...',
)



class GRPCOverviewStats(BaseModel):
    """
    Overview statistics for gRPC requests.

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

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

    total: int = Field(description='Total requests in period')
    successful: int = Field(description='Successful requests')
    errors: int = Field(description='Error requests')
    cancelled: int = Field(description='Cancelled requests')
    timeout: int = Field(description='Timeout requests')
    success_rate: float = Field(description='Success rate percentage')
    avg_duration_ms: float = Field(description='Average duration in milliseconds')
    p95_duration_ms: float | None = Field(None, description='95th percentile duration in mill...')
    period_hours: int = Field(description='Statistics period in hours')
    server: GRPCServerStatus = ...



class RecentRequest(BaseModel):
    """
    Recent request information.

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

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

    id: int = Field(description='Database ID')
    request_id: str = Field(description='Request ID')
    service_name: str = Field(description='Service name')
    method_name: str = Field(description='Method name')
    status: str = Field(description='Request status')
    duration_ms: int | None = Field(None, description='Duration in milliseconds')
    grpc_status_code: str | None = Field(None, description='gRPC status code')
    error_message: str | None = Field(None, description='Error message if failed')
    created_at: str = Field(description='Request timestamp')
    client_ip: str | None = Field(None, description='Client IP address')
    user_id: int | None = Field(None, description='User ID (if authenticated)')
    username: str | None = Field(None, description='Username (if authenticated)')
    is_authenticated: bool | None = Field(None, description='Whether request was authenticated')
    api_key_id: int | None = Field(None, description='API Key ID (if used)')
    api_key_name: str | None = Field(None, description='API Key name (if used)')



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



