# 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 (
    PatchedProxyRequestProxyMode,
    PatchedProxyRequestProxyType,
    PatchedProxyRequestStatus,
    PatchedProxyTestRequestTestType,
)


class ProxyAssignment(BaseModel):
    """
    Serializer for ProxyAssignment model.

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

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

    id: str = ...
    proxy: str = ...
    parser_id: str = Field(description='Parser using this proxy', max_length=255)
    session_id: str | None = Field(None, description='Session ID if applicable', max_length=255)
    is_active: bool | None = None
    priority: int | None = Field(
    None,
    description='Assignment priority (1-10)',
    ge=0,
    le=2147483647,
)
    requests_made: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    bytes_transferred: int | None = Field(None, ge=0, le=9223372036854775808)
    avg_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    min_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    max_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    assigned_at: datetime.datetime = ...
    last_used: datetime.datetime | None = None
    released_at: datetime.datetime | None = None
    success_rate: float = ...
    duration_seconds: float = ...



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



class ProxyAssignmentRequest(BaseModel):
    """
    Serializer for ProxyAssignment model.

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

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

    proxy: str = ...
    parser_id: str = Field(description='Parser using this proxy', min_length=1, max_length=255)
    session_id: str | None = Field(None, description='Session ID if applicable', max_length=255)
    is_active: bool | None = None
    priority: int | None = Field(
    None,
    description='Assignment priority (1-10)',
    ge=0,
    le=2147483647,
)
    requests_made: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    bytes_transferred: int | None = Field(None, ge=0, le=9223372036854775808)
    avg_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    min_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    max_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    last_used: datetime.datetime | None = None
    released_at: datetime.datetime | None = None



class PatchedProxyAssignmentRequest(BaseModel):
    """
    Serializer for ProxyAssignment model.

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

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

    proxy: str | None = None
    parser_id: str | None = Field(
    None,
    description='Parser using this proxy',
    min_length=1,
    max_length=255,
)
    session_id: str | None = Field(None, description='Session ID if applicable', max_length=255)
    is_active: bool | None = None
    priority: int | None = Field(
    None,
    description='Assignment priority (1-10)',
    ge=0,
    le=2147483647,
)
    requests_made: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    bytes_transferred: int | None = Field(None, ge=0, le=9223372036854775808)
    avg_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    min_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    max_response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    last_used: datetime.datetime | None = None
    released_at: datetime.datetime | None = None



class Proxy(BaseModel):
    """
    Serializer for Proxy model.

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

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

    id: str = ...
    host: str = Field(description='Proxy host/IP address', max_length=255)
    port: int = Field(description='Proxy port', ge=1, le=65535)
    proxy_type: PatchedProxyRequestProxyType | None = Field(
    None,
    description='* `http` - HTTP * `https` - HTTP...',
)
    proxy_mode: PatchedProxyRequestProxyMode | None = Field(
    None,
    description='Proxy operation mode  * `static`...',
)
    username: str | None = Field(None, description='Proxy username', max_length=255)
    password: str | None = Field(None, description='Proxy password', max_length=255)
    provider: str | None = Field(None, description='Proxy provider (ORM reference)')
    provider_id: str | None = Field(None, description='Proxy provider (ORM reference)')
    country: str | None = Field(None, description='ISO country code', max_length=2)
    region: str | None = Field(None, description='Region/state', max_length=100)
    city: str | None = Field(None, description='City', max_length=100)
    status: PatchedProxyRequestStatus | None = Field(
    None,
    description='* `active` - Active * `inactive`...',
)
    is_active: bool | None = None
    last_checked: datetime.datetime | None = None
    expires_at: datetime.datetime | None = Field(None, description='Proxy expiration date (UTC)')
    response_time_ms: int | None = Field(
    None,
    description='Average response time',
    ge=0,
    le=2147483647,
)
    success_rate: float | None = Field(
    None,
    description='Success rate percentage',
    ge=0.0,
    le=100.0,
)
    uptime_percentage: float | None = Field(
    None,
    description='Uptime percentage',
    ge=0.0,
    le=100.0,
)
    total_requests: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    max_concurrent_requests: int | None = Field(
    None,
    description='Max concurrent requests',
    ge=0,
    le=2147483647,
)
    requests_per_minute: int | None = Field(
    None,
    description='Requests per minute limit',
    ge=0,
    le=2147483647,
)
    cost_per_gb: Any | None = Field(
    None,
    description='Cost per GB of traffic',
    pattern='^-?\\d{0,6}(?:\\.\\d{0,4})?$',
)
    monthly_cost: Any | None = Field(
    None,
    description='Monthly cost',
    pattern='^-?\\d{0,8}(?:\\.\\d{0,2})?$',
)
    metadata: dict[str, Any] | None = Field(
    None,
    description='Full provider response and sync ...',
)
    config: dict[str, Any] | None = Field(None, description='Proxy configuration (gateway, se...')
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    created_at: datetime.datetime = ...
    updated_at: datetime.datetime = ...
    last_synced_at: datetime.datetime | None = Field(
    None,
    description='Last synchronization with provider',
)
    proxy_url: Any = ...
    is_healthy: bool = ...
    current_load: float = ...



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



class ProxyRequest(BaseModel):
    """
    Serializer for Proxy model.

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

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

    host: str = Field(description='Proxy host/IP address', min_length=1, max_length=255)
    port: int = Field(description='Proxy port', ge=1, le=65535)
    proxy_type: PatchedProxyRequestProxyType | None = Field(
    None,
    description='* `http` - HTTP * `https` - HTTP...',
)
    proxy_mode: PatchedProxyRequestProxyMode | None = Field(
    None,
    description='Proxy operation mode  * `static`...',
)
    username: str | None = Field(None, description='Proxy username', max_length=255)
    password: str | None = Field(None, description='Proxy password', max_length=255)
    provider: str | None = Field(None, description='Proxy provider (ORM reference)')
    country: str | None = Field(None, description='ISO country code', max_length=2)
    region: str | None = Field(None, description='Region/state', max_length=100)
    city: str | None = Field(None, description='City', max_length=100)
    status: PatchedProxyRequestStatus | None = Field(
    None,
    description='* `active` - Active * `inactive`...',
)
    is_active: bool | None = None
    last_checked: datetime.datetime | None = None
    expires_at: datetime.datetime | None = Field(None, description='Proxy expiration date (UTC)')
    response_time_ms: int | None = Field(
    None,
    description='Average response time',
    ge=0,
    le=2147483647,
)
    success_rate: float | None = Field(
    None,
    description='Success rate percentage',
    ge=0.0,
    le=100.0,
)
    uptime_percentage: float | None = Field(
    None,
    description='Uptime percentage',
    ge=0.0,
    le=100.0,
)
    total_requests: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    max_concurrent_requests: int | None = Field(
    None,
    description='Max concurrent requests',
    ge=0,
    le=2147483647,
)
    requests_per_minute: int | None = Field(
    None,
    description='Requests per minute limit',
    ge=0,
    le=2147483647,
)
    cost_per_gb: Any | None = Field(
    None,
    description='Cost per GB of traffic',
    pattern='^-?\\d{0,6}(?:\\.\\d{0,4})?$',
)
    monthly_cost: Any | None = Field(
    None,
    description='Monthly cost',
    pattern='^-?\\d{0,8}(?:\\.\\d{0,2})?$',
)
    metadata: dict[str, Any] | None = Field(
    None,
    description='Full provider response and sync ...',
)
    config: dict[str, Any] | None = Field(None, description='Proxy configuration (gateway, se...')
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    last_synced_at: datetime.datetime | None = Field(
    None,
    description='Last synchronization with provider',
)



class PatchedProxyRequest(BaseModel):
    """
    Serializer for Proxy model.

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

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

    host: str | None = Field(
    None,
    description='Proxy host/IP address',
    min_length=1,
    max_length=255,
)
    port: int | None = Field(None, description='Proxy port', ge=1, le=65535)
    proxy_type: PatchedProxyRequestProxyType | None = Field(
    None,
    description='* `http` - HTTP * `https` - HTTP...',
)
    proxy_mode: PatchedProxyRequestProxyMode | None = Field(
    None,
    description='Proxy operation mode  * `static`...',
)
    username: str | None = Field(None, description='Proxy username', max_length=255)
    password: str | None = Field(None, description='Proxy password', max_length=255)
    provider: str | None = Field(None, description='Proxy provider (ORM reference)')
    country: str | None = Field(None, description='ISO country code', max_length=2)
    region: str | None = Field(None, description='Region/state', max_length=100)
    city: str | None = Field(None, description='City', max_length=100)
    status: PatchedProxyRequestStatus | None = Field(
    None,
    description='* `active` - Active * `inactive`...',
)
    is_active: bool | None = None
    last_checked: datetime.datetime | None = None
    expires_at: datetime.datetime | None = Field(None, description='Proxy expiration date (UTC)')
    response_time_ms: int | None = Field(
    None,
    description='Average response time',
    ge=0,
    le=2147483647,
)
    success_rate: float | None = Field(
    None,
    description='Success rate percentage',
    ge=0.0,
    le=100.0,
)
    uptime_percentage: float | None = Field(
    None,
    description='Uptime percentage',
    ge=0.0,
    le=100.0,
)
    total_requests: int | None = Field(None, ge=0, le=2147483647)
    successful_requests: int | None = Field(None, ge=0, le=2147483647)
    failed_requests: int | None = Field(None, ge=0, le=2147483647)
    max_concurrent_requests: int | None = Field(
    None,
    description='Max concurrent requests',
    ge=0,
    le=2147483647,
)
    requests_per_minute: int | None = Field(
    None,
    description='Requests per minute limit',
    ge=0,
    le=2147483647,
)
    cost_per_gb: Any | None = Field(
    None,
    description='Cost per GB of traffic',
    pattern='^-?\\d{0,6}(?:\\.\\d{0,4})?$',
)
    monthly_cost: Any | None = Field(
    None,
    description='Monthly cost',
    pattern='^-?\\d{0,8}(?:\\.\\d{0,2})?$',
)
    metadata: dict[str, Any] | None = Field(
    None,
    description='Full provider response and sync ...',
)
    config: dict[str, Any] | None = Field(None, description='Proxy configuration (gateway, se...')
    error_count: int | None = Field(None, ge=0, le=2147483647)
    last_error: str | None = None
    last_error_at: datetime.datetime | None = None
    last_synced_at: datetime.datetime | None = Field(
    None,
    description='Last synchronization with provider',
)



class ProxyRotation(BaseModel):
    """
    Serializer for ProxyRotation model.

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

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

    id: str = ...
    name: str = Field(description='Rotation configuration name', max_length=200)
    parser_ids: dict[str, Any] | None = Field(None, description='Parser IDs using this rotation')
    rotation_interval_minutes: int | None = Field(
    None,
    description='Minutes between rotations',
    ge=0,
    le=2147483647,
)
    max_requests_per_proxy: int | None = Field(
    None,
    description='Max requests before rotation',
    ge=0,
    le=2147483647,
)
    max_errors_per_proxy: int | None = Field(
    None,
    description='Max errors before rotation',
    ge=0,
    le=2147483647,
)
    allowed_countries: dict[str, Any] | None = Field(None, description='Allowed country codes')
    allowed_providers: dict[str, Any] | None = Field(None, description='Allowed providers')
    min_success_rate: float | None = Field(None, description='Minimum success rate')
    max_response_time_ms: int | None = Field(
    None,
    description='Maximum response time',
    ge=0,
    le=2147483647,
)
    is_active: bool | None = None
    total_rotations: int | None = Field(None, ge=0, le=2147483647)
    last_rotation: datetime.datetime | None = None
    created_at: datetime.datetime = ...
    updated_at: datetime.datetime = ...



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



class ProxyRotationRequest(BaseModel):
    """
    Serializer for ProxyRotation model.

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

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

    name: str = Field(description='Rotation configuration name', min_length=1, max_length=200)
    parser_ids: dict[str, Any] | None = Field(None, description='Parser IDs using this rotation')
    rotation_interval_minutes: int | None = Field(
    None,
    description='Minutes between rotations',
    ge=0,
    le=2147483647,
)
    max_requests_per_proxy: int | None = Field(
    None,
    description='Max requests before rotation',
    ge=0,
    le=2147483647,
)
    max_errors_per_proxy: int | None = Field(
    None,
    description='Max errors before rotation',
    ge=0,
    le=2147483647,
)
    allowed_countries: dict[str, Any] | None = Field(None, description='Allowed country codes')
    allowed_providers: dict[str, Any] | None = Field(None, description='Allowed providers')
    min_success_rate: float | None = Field(None, description='Minimum success rate')
    max_response_time_ms: int | None = Field(
    None,
    description='Maximum response time',
    ge=0,
    le=2147483647,
)
    is_active: bool | None = None
    total_rotations: int | None = Field(None, ge=0, le=2147483647)
    last_rotation: datetime.datetime | None = None



class PatchedProxyRotationRequest(BaseModel):
    """
    Serializer for ProxyRotation model.

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

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

    name: str | None = Field(
    None,
    description='Rotation configuration name',
    min_length=1,
    max_length=200,
)
    parser_ids: dict[str, Any] | None = Field(None, description='Parser IDs using this rotation')
    rotation_interval_minutes: int | None = Field(
    None,
    description='Minutes between rotations',
    ge=0,
    le=2147483647,
)
    max_requests_per_proxy: int | None = Field(
    None,
    description='Max requests before rotation',
    ge=0,
    le=2147483647,
)
    max_errors_per_proxy: int | None = Field(
    None,
    description='Max errors before rotation',
    ge=0,
    le=2147483647,
)
    allowed_countries: dict[str, Any] | None = Field(None, description='Allowed country codes')
    allowed_providers: dict[str, Any] | None = Field(None, description='Allowed providers')
    min_success_rate: float | None = Field(None, description='Minimum success rate')
    max_response_time_ms: int | None = Field(
    None,
    description='Maximum response time',
    ge=0,
    le=2147483647,
)
    is_active: bool | None = None
    total_rotations: int | None = Field(None, ge=0, le=2147483647)
    last_rotation: datetime.datetime | None = None



class ProxyTest(BaseModel):
    """
    Serializer for ProxyTest model.

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

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

    id: str = ...
    proxy: str = ...
    test_url: str | None = Field(None, description='URL used for testing', max_length=200)
    test_type: PatchedProxyTestRequestTestType | None = Field(
    None,
    description='* `connectivity` - Connectivity ...',
)
    is_successful: bool | None = None
    response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    response_code: int | None = Field(None, ge=0, le=2147483647)
    response_data: dict[str, Any] | None = Field(None, description='Test response data')
    error_message: str | None = None
    error_type: str | None = Field(None, max_length=100)
    detected_ip: str | None = None
    detected_country: str | None = Field(None, max_length=2)
    detected_city: str | None = Field(None, max_length=100)
    tested_at: datetime.datetime = ...



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



class ProxyTestRequest(BaseModel):
    """
    Serializer for ProxyTest model.

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

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

    proxy: str = ...
    test_url: str | None = Field(
    None,
    description='URL used for testing',
    min_length=1,
    max_length=200,
)
    test_type: PatchedProxyTestRequestTestType | None = Field(
    None,
    description='* `connectivity` - Connectivity ...',
)
    is_successful: bool | None = None
    response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    response_code: int | None = Field(None, ge=0, le=2147483647)
    response_data: dict[str, Any] | None = Field(None, description='Test response data')
    error_message: str | None = None
    error_type: str | None = Field(None, max_length=100)
    detected_ip: str | None = Field(None, min_length=1)
    detected_country: str | None = Field(None, max_length=2)
    detected_city: str | None = Field(None, max_length=100)



class PatchedProxyTestRequest(BaseModel):
    """
    Serializer for ProxyTest model.

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

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

    proxy: str | None = None
    test_url: str | None = Field(
    None,
    description='URL used for testing',
    min_length=1,
    max_length=200,
)
    test_type: PatchedProxyTestRequestTestType | None = Field(
    None,
    description='* `connectivity` - Connectivity ...',
)
    is_successful: bool | None = None
    response_time_ms: int | None = Field(None, ge=0, le=2147483647)
    response_code: int | None = Field(None, ge=0, le=2147483647)
    response_data: dict[str, Any] | None = Field(None, description='Test response data')
    error_message: str | None = None
    error_type: str | None = Field(None, max_length=100)
    detected_ip: str | None = Field(None, min_length=1)
    detected_country: str | None = Field(None, max_length=2)
    detected_city: str | None = Field(None, max_length=100)



