# generated by datamodel-codegen:
#   filename:  performance-test.json
#   timestamp: 2026-01-25T13:38:23+00:00

from __future__ import annotations

from enum import StrEnum
from typing import Annotated, Any

from pydantic import AnyUrl, AwareDatetime, BaseModel, ConfigDict, Field


class Method(StrEnum):
    """
    HTTP method
    """

    GET = 'GET'
    POST = 'POST'
    PUT = 'PUT'
    DELETE = 'DELETE'
    PATCH = 'PATCH'
    HEAD = 'HEAD'
    OPTIONS = 'OPTIONS'


class ResourceType(StrEnum):
    """
    Type of resource requested
    """

    document = 'document'
    stylesheet = 'stylesheet'
    script = 'script'
    image = 'image'
    fetch = 'fetch'
    xhr = 'xhr'
    other = 'other'


class ResponseTiming(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    dns: float
    """
    DNS lookup time in milliseconds
    """
    tcp: float
    """
    TCP connection time in milliseconds
    """
    ssl: float
    """
    SSL/TLS handshake time in milliseconds
    """
    ttfb: float
    """
    Time to first byte in milliseconds
    """
    download: float
    """
    Download time in milliseconds
    """
    total: float
    """
    Total request time in milliseconds
    """


class Status(StrEnum):
    """
    Test status
    """

    draft = 'draft'
    configured = 'configured'
    running = 'running'
    completed = 'completed'
    archived = 'archived'


class PerformanceTestMetadata(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: str
    """
    Unique test identifier
    """
    name: str
    """
    Test name
    """
    description: str
    """
    Test description
    """
    tags: list[str]
    """
    Test tags for categorization
    """
    parentID: str | None = None
    """
    Parent folder ID
    """
    createdAt: AwareDatetime
    """
    Creation timestamp
    """
    updatedAt: AwareDatetime
    """
    Last update timestamp
    """
    createdBy: str
    """
    Creator identifier
    """
    version: Annotated[int, Field(ge=1)]
    """
    Test version number
    """
    status: Status
    """
    Test status
    """
    lastRun: AwareDatetime | None = None
    """
    Last execution timestamp
    """


class RefreshMethod(StrEnum):
    """
    HTTP method for refresh request
    """

    GET = 'GET'
    POST = 'POST'
    PUT = 'PUT'


class TokenRefreshConfig(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    refresh_url: AnyUrl
    """
    Token refresh endpoint URL
    """
    refresh_method: RefreshMethod = RefreshMethod.POST
    """
    HTTP method for refresh request
    """
    refresh_body: Any | None = None
    """
    Request body for token refresh
    """
    refresh_headers: dict[str, str] | None = None
    """
    Headers for refresh request
    """
    token_path: str
    """
    JSON path to extract token from response
    """
    token_header: str | None = 'Authorization'
    """
    Header name for token
    """
    token_prefix: str | None = 'Bearer'
    """
    Token prefix
    """
    refresh_interval: int | None = None
    """
    Refresh interval in seconds
    """


class Credential(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    headers: dict[str, str]
    """
    Headers for this credential set
    """
    user_id: str | None = None
    """
    User identifier
    """


class RotationStrategy(StrEnum):
    """
    Credential rotation strategy
    """

    round_robin = 'round_robin'
    random = 'random'


class CredentialRotationConfig(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    credentials: list[Credential]
    """
    Array of credential sets
    """
    rotation_strategy: RotationStrategy = RotationStrategy.round_robin
    """
    Credential rotation strategy
    """


class LoadTestThresholds(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    maxResponseTime: Annotated[int, Field(ge=0)]
    """
    Maximum acceptable response time in milliseconds
    """
    maxErrorRate: Annotated[float, Field(ge=0.0, le=1.0)]
    """
    Maximum acceptable error rate (0-1)
    """
    minThroughput: Annotated[float, Field(ge=0.0)]
    """
    Minimum requests per second
    """


class ResponseTimeMetrics(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    min: float
    """
    Minimum response time
    """
    max: float
    """
    Maximum response time
    """
    mean: float
    """
    Mean response time
    """
    median: float
    """
    Median response time
    """
    p90: float
    """
    90th percentile response time
    """
    p95: float
    """
    95th percentile response time
    """
    p99: float
    """
    99th percentile response time
    """


class BandwidthMetrics(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    sent: int
    """
    Total bytes sent
    """
    received: int
    """
    Total bytes received
    """
    avgSentPerSecond: float
    """
    Average bytes sent per second
    """
    avgReceivedPerSecond: float
    """
    Average bytes received per second
    """


class RequestExecution(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    timestamp: float
    """
    Execution timestamp
    """
    statusCode: int
    """
    HTTP status code
    """
    responseTime: float
    """
    Response time in milliseconds
    """
    size: int
    """
    Response size in bytes
    """
    success: bool
    """
    Whether the request was successful
    """
    error: str | None = None
    """
    Error message if failed
    """


class TimelineDataPoint(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    timestamp: float
    """
    Data point timestamp
    """
    activeUsers: int
    """
    Number of active users at this point
    """
    requestsPerSecond: float
    """
    Requests per second at this point
    """
    avgResponseTime: float
    """
    Average response time at this point
    """
    errorRate: float
    """
    Error rate at this point
    """


class RecordedResponse(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    status: int
    """
    HTTP status code
    """
    statusText: str
    """
    HTTP status text
    """
    headers: dict[str, str]
    """
    Response headers
    """
    body: str | None = None
    """
    Response body
    """
    size: int
    """
    Response size in bytes
    """
    timing: ResponseTiming
    """
    Response timing breakdown
    """


class AuthConfig(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    token_refresh: TokenRefreshConfig | None = None
    """
    Token refresh configuration
    """
    credential_rotation: CredentialRotationConfig | None = None
    """
    Credential rotation configuration
    """
    header_override: dict[str, str] | None = None
    """
    Header override configuration
    """


class LoadTestConfiguration(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    targetUrl: AnyUrl
    """
    Base URL for the load test
    """
    duration: Annotated[int, Field(ge=1)]
    """
    Test duration in seconds
    """
    virtualUsers: Annotated[int, Field(ge=1)]
    """
    Number of concurrent virtual users
    """
    rampUpTime: Annotated[int | None, Field(ge=0)] = None
    """
    Time to ramp up to full load in seconds
    """
    thinkTime: Annotated[int | None, Field(ge=0)] = None
    """
    Delay between requests per user in milliseconds
    """
    includeRequests: list[str]
    """
    IDs of requests to include in load test
    """
    thresholds: LoadTestThresholds
    """
    Pass/fail thresholds
    """
    authConfig: AuthConfig | None = None
    """
    Authentication configuration
    """


class AggregateMetrics(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    totalRequests: int
    """
    Total number of requests executed
    """
    successfulRequests: int
    """
    Number of successful requests
    """
    failedRequests: int
    """
    Number of failed requests
    """
    errorRate: float
    """
    Error rate (0-1)
    """
    throughput: float
    """
    Requests per second
    """
    responseTime: ResponseTimeMetrics
    """
    Response time statistics
    """
    bandwidth: BandwidthMetrics
    """
    Bandwidth usage metrics
    """


class RequestResults(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    requestId: str
    """
    Request identifier
    """
    url: AnyUrl
    """
    Request URL
    """
    method: str
    """
    HTTP method
    """
    executions: list[RequestExecution]
    """
    Individual execution results
    """


class RecordedRequest(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: str
    """
    Unique request identifier
    """
    url: AnyUrl
    """
    Request URL
    """
    method: Method
    """
    HTTP method
    """
    headers: dict[str, str]
    """
    Request headers
    """
    body: str | None = None
    """
    Request body
    """
    timestamp: float
    """
    Request timestamp in milliseconds
    """
    response: RecordedResponse | None = None
    """
    Response data
    """
    resourceType: ResourceType
    """
    Type of resource requested
    """
    initiator: str | None = None
    """
    What triggered this request
    """


class PerformanceTestResults(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    testId: str
    """
    Test identifier
    """
    startTime: float
    """
    Test start timestamp
    """
    endTime: float
    """
    Test end timestamp
    """
    duration: float
    """
    Test duration in seconds
    """
    metrics: AggregateMetrics
    """
    Aggregate performance metrics
    """
    requestResults: list[RequestResults]
    """
    Per-request execution results
    """
    timeline: list[TimelineDataPoint]
    """
    Time-series data for charts
    """
    passed: bool
    """
    Whether the test passed
    """
    failureReasons: list[str] | None = None
    """
    Reasons for test failure
    """


class PerformanceTest(BaseModel):
    """
    Performance test definition for load testing and API monitoring
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    metadata: PerformanceTestMetadata
    """
    Test metadata and configuration
    """
    recordedRequests: list[RecordedRequest]
    """
    HTTP requests recorded during test creation
    """
    loadTestConfig: LoadTestConfiguration
    """
    Load test execution configuration
    """
    filterPatterns: list[str] | None = None
    """
    URL patterns for filtering recorded requests
    """
    onlySameDomain: bool | None = None
    """
    Restrict recording to same domain only
    """
    results: PerformanceTestResults | None = None
    """
    Results from load test execution
    """
