"""
Pydantic Models for CMDB - system/session_ttl

Runtime validation models for system/session_ttl configuration.
Generated from FortiOS schema version unknown.
"""

from __future__ import annotations

from pydantic import BaseModel, Field
from typing import Any, Optional

# ============================================================================
# Child Table Models
# ============================================================================

class SessionTtlPort(BaseModel):
    """
    Child table model for port.
    
    Session TTL port.
    """
    
    class Config:
        """Pydantic model configuration."""
        extra = "allow"  # Allow additional fields from API
        str_strip_whitespace = True
    
    id: int = Field(ge=0, le=65535, default=0, description="Table entry ID.")    
    protocol: int = Field(ge=0, le=255, default=0, description="Protocol (0 - 255).")    
    start_port: int = Field(ge=0, le=65535, default=0, description="Start port number.")    
    end_port: int = Field(ge=0, le=65535, default=0, description="End port number.")    
    timeout: str | None = Field(default="", description="Session timeout (TTL).")    
    refresh_direction: Literal["both", "outgoing", "incoming"] | None = Field(default="both", description="Configure refresh direction.")
# ============================================================================
# Enum Definitions (for fields with 4+ allowed values)
# ============================================================================


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

class SessionTtlModel(BaseModel):
    """
    Pydantic model for system/session_ttl configuration.
    
    Configure global session TTL timers for this FortiGate.
    
    Validation Rules:        - default: pattern=        - port: 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
    # ========================================================================
    
    default: str | None = Field(default="", description="Default timeout.")    
    port: list[Port] = Field(default=None, description="Session TTL port.")    
    # ========================================================================
    # 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]) -> "SessionTtlModel":
        """
        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__ = [
    "SessionTtlModel",    "SessionTtlPort",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-17T04:31:40.387828Z
# ============================================================================