"""
Pydantic Models for CMDB - switch_controller/storm_control

Runtime validation models for switch_controller/storm_control configuration.
Generated from FortiOS schema version unknown.
"""

from __future__ import annotations

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

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


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

class StormControlModel(BaseModel):
    """
    Pydantic model for switch_controller/storm_control configuration.
    
    Configure FortiSwitch storm control.
    
    Validation Rules:        - rate: min=0 max=10000000 pattern=        - burst_size_level: min=0 max=4 pattern=        - unknown_unicast: pattern=        - unknown_multicast: pattern=        - broadcast: 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
    # ========================================================================
    
    rate: int | None = Field(ge=0, le=10000000, default=500, description="Rate in packets per second at which storm control drops excess traffic(0-10000000, default=500, drop-all=0).")    
    burst_size_level: int | None = Field(ge=0, le=4, default=0, description="Increase level to handle bursty traffic (0 - 4, default = 0).")    
    unknown_unicast: Literal["enable", "disable"] | None = Field(default="disable", description="Enable/disable storm control to drop unknown unicast traffic.")    
    unknown_multicast: Literal["enable", "disable"] | None = Field(default="disable", description="Enable/disable storm control to drop unknown multicast traffic.")    
    broadcast: Literal["enable", "disable"] | None = Field(default="disable", description="Enable/disable storm control to drop broadcast traffic.")    
    # ========================================================================
    # 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]) -> "StormControlModel":
        """
        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__ = [
    "StormControlModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-17T17:56:13.103245Z
# ============================================================================