# generated by datamodel-codegen:
#   filename:  flow-validation.json
#   timestamp: 2026-01-25T13:38:27+00:00

from __future__ import annotations

from enum import StrEnum
from typing import Annotated

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field


class Type(StrEnum):
    """
    Type of warning
    """

    missing_selector = 'missing-selector'
    infinite_loop = 'infinite-loop'
    unreachable_node = 'unreachable-node'
    missing_condition = 'missing-condition'
    invalid_reference = 'invalid-reference'
    missing_action_reference = 'missing-action-reference'
    circular_dependency = 'circular-dependency'
    duplicate_id = 'duplicate-id'
    invalid_variable = 'invalid-variable'
    missing_variable = 'missing-variable'
    type_mismatch = 'type-mismatch'
    performance_issue = 'performance-issue'
    security_risk = 'security-risk'


class Category(StrEnum):
    """
    Category of the warning
    """

    logic = 'logic'
    performance = 'performance'
    security = 'security'
    usability = 'usability'
    compatibility = 'compatibility'


class WarningSeverity(StrEnum):
    """
    Severity level of the warning
    """

    minor = 'minor'
    medium = 'medium'
    critical = 'critical'
    info = 'info'


class LoopInfo(BaseModel):
    """
    Information about a detected loop
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    nodes: list[str]
    """
    Node IDs that form the loop
    """
    hasExitCondition: bool
    """
    Whether the loop has a proper exit condition
    """
    severity: WarningSeverity
    description: str
    """
    Description of the loop issue
    """
    maxIterations: int | None = None
    """
    Maximum iterations if detectable
    """
    isInfinite: bool | None = None
    """
    Whether this appears to be an infinite loop
    """


class WarningsBySeverity(BaseModel):
    """
    Count of warnings by severity
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    minor: Annotated[int | None, Field(ge=0)] = None
    medium: Annotated[int | None, Field(ge=0)] = None
    critical: Annotated[int | None, Field(ge=0)] = None
    info: Annotated[int | None, Field(ge=0)] = None


class ValidationSummary(BaseModel):
    """
    Summary statistics of validation results
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    totalNodes: Annotated[int, Field(ge=0)]
    """
    Total number of nodes in the flow
    """
    totalEdges: Annotated[int, Field(ge=0)]
    """
    Total number of edges in the flow
    """
    warningCount: Annotated[int, Field(ge=0)]
    """
    Total number of warnings
    """
    errorCount: Annotated[int, Field(ge=0)]
    """
    Total number of errors
    """
    criticalCount: Annotated[int | None, Field(ge=0)] = None
    """
    Number of critical severity issues
    """
    warningsByType: dict[str, int] | None = None
    """
    Count of warnings by type
    """
    warningsBySeverity: WarningsBySeverity | None = None
    """
    Count of warnings by severity
    """


class ConfigValidation(BaseModel):
    """
    Validation of node configuration
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    isValid: bool | None = None
    missingFields: list[str] | None = None
    invalidFields: list[str] | None = None
    typeErrors: list[str] | None = None


class FlowWarning(BaseModel):
    """
    Flow validation warning or error
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: str
    """
    Unique warning identifier
    """
    type: Type
    """
    Type of warning
    """
    severity: WarningSeverity
    nodeId: str
    """
    ID of the node that triggered the warning
    """
    nodeName: str
    """
    Name of the node that triggered the warning
    """
    message: str
    """
    Warning message
    """
    description: str
    """
    Detailed description of the warning
    """
    affectedNodes: list[str] | None = None
    """
    List of other affected node IDs
    """
    suggestion: str | None = None
    """
    Suggested fix for the warning
    """
    category: Category | None = None
    """
    Category of the warning
    """
    createdAt: AwareDatetime | None = None
    """
    When the warning was detected
    """


class LoopDetectionResult(BaseModel):
    """
    Result of loop detection analysis
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    hasLoops: bool
    """
    Whether loops were detected in the flow
    """
    loops: list[LoopInfo]
    """
    Information about detected loops
    """
    totalLoops: Annotated[int | None, Field(ge=0)] = None
    """
    Total number of loops detected
    """
    infiniteLoops: Annotated[int | None, Field(ge=0)] = None
    """
    Number of potentially infinite loops
    """


class FlowValidationResult(BaseModel):
    """
    Complete result of flow validation
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    flowId: str
    """
    ID of the validated flow
    """
    flowName: str | None = None
    """
    Name of the validated flow
    """
    isValid: bool
    """
    Whether the flow is valid
    """
    warnings: list[FlowWarning]
    """
    List of warnings found
    """
    errors: list[FlowWarning]
    """
    List of errors found (critical warnings)
    """
    summary: ValidationSummary
    validatedAt: AwareDatetime | None = None
    """
    When validation was performed
    """
    validationTime: Annotated[float | None, Field(ge=0.0)] = None
    """
    Time taken for validation in seconds
    """


class NodeValidationResult(BaseModel):
    """
    Validation result for a specific node
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    nodeId: str
    """
    ID of the validated node
    """
    nodeType: str
    """
    Type of the node
    """
    isValid: bool
    """
    Whether the node is valid
    """
    warnings: list[FlowWarning] | None = None
    """
    Warnings specific to this node
    """
    configValidation: ConfigValidation | None = None
    """
    Validation of node configuration
    """


class FlowValidation(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    warnings: list[FlowWarning] | None = None
    loopDetections: list[LoopDetectionResult] | None = None
    validationResults: list[FlowValidationResult] | None = None


class FlowValidationModels(BaseModel):
    """
    Schema for flow validation warnings and errors
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    flowValidation: FlowValidation | None = None
