"""
Pydantic Models for CMDB - web_proxy/fast_fallback

Runtime validation models for web_proxy/fast_fallback configuration.
Generated from FortiOS schema version unknown.

Example Usage:
    >>> from hfortix_fortios.models.cmdb.web_proxy.fast_fallback import 
    >>>
    >>> # Create with validation
    >>> obj = (
    ...     name=1,
    ...     name="example",
    ... )
    >>>
    >>> # Validation happens automatically
    >>> # ValidationError raised if constraints violated
"""

from __future__ import annotations

from pydantic import BaseModel, Field, field_validator
from typing import Any, Literal, Optional
from enum import Enum

# ============================================================================
# Enum Definitions (for fields with 4+ allowed values)
# ============================================================================

class FastFallbackProtocolEnum(str, Enum):
    """Allowed values for protocol field."""
    IPV4_FIRST = "IPv4-first"    IPV6_FIRST = "IPv6-first"    IPV4_ONLY = "IPv4-only"    IPV6_ONLY = "IPv6-only"

# ============================================================================
# Main Model
# ============================================================================

class FastFallbackModel(BaseModel):
    """
    Pydantic model for web_proxy/fast_fallback configuration.
    
    Proxy destination connection fast-fallback.
    
    Validation Rules:        - name: max_length=63 pattern=        - status: pattern=        - connection_mode: pattern=        - protocol: pattern=        - connection_timeout: min=200 max=1800000 pattern=    """
    
    class Config:
        """Pydantic model configuration."""
        extra = "allow"  # Allow additional fields from API
        str_strip_whitespace = True
        validate_assignment = True  # Validate on attribute assignment
        use_enum_values = True  # Use enum values instead of names
    
    # ========================================================================
    # Model Fields
    # ========================================================================
    
    name: str | None = Field(max_length=63, default="", description="Configure a name for the fast-fallback entry.")    
    status: Literal["enable", "disable"] | None = Field(default="enable", description="Enable/disable the fast-fallback entry.")    
    connection_mode: Literal["sequentially", "simultaneously"] | None = Field(default="sequentially", description="Connection mode for multiple destinations.")    
    protocol: ProtocolEnum | None = Field(default="IPv4-first", description="Connection protocols for multiple destinations.")    
    connection_timeout: int | None = Field(ge=200, le=1800000, default=200, description="Number of milliseconds to wait before starting another connection (200 - 1800000, default = 200). For sequential connection-mode only.")    
    # ========================================================================
    # Custom Validators
    # ========================================================================
    
    # ========================================================================
    # Helper Methods
    # ========================================================================
    
    def to_fortios_dict(self) -> dict[str, Any]:
        """
        Convert model to FortiOS API payload format.
        
        Returns:
            Dict suitable for POST/PUT operations
        """
        # Export with exclude_none to avoid sending null values
        return self.model_dump(exclude_none=True, by_alias=True)
    
    @classmethod
    def from_fortios_response(cls, data: dict[str, Any]) -> "":
        """
        Create model instance from FortiOS API response.
        
        Args:
            data: Response data from API
            
        Returns:
            Validated model instance
        """
        return cls(**data)

# ============================================================================
# Type Aliases for Convenience
# ============================================================================

Dict = dict[str, Any]  # For backward compatibility

# ============================================================================
# Module Exports
# ============================================================================

__all__ = [
    "FastFallbackModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-09T09:47:40.270765Z
# ============================================================================