"""
Pydantic Models for CMDB - switch_controller/stp_settings

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

from __future__ import annotations

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

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


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

class StpSettingsModel(BaseModel):
    """
    Pydantic model for switch_controller/stp_settings configuration.
    
    Configure FortiSwitch spanning tree protocol (STP).
    
    Validation Rules:        - name: max_length=31 pattern=        - revision: min=0 max=65535 pattern=        - hello_time: min=1 max=10 pattern=        - forward_time: min=4 max=30 pattern=        - max_age: min=6 max=40 pattern=        - max_hops: min=1 max=40 pattern=        - pending_timer: min=1 max=15 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=31, default=None, description="Name of global STP settings configuration.")    
    revision: int | None = Field(ge=0, le=65535, default=0, description="STP revision number (0 - 65535).")    
    hello_time: int | None = Field(ge=1, le=10, default=2, description="Period of time between successive STP frame Bridge Protocol Data Units (BPDUs) sent on a port (1 - 10 sec, default = 2).")    
    forward_time: int | None = Field(ge=4, le=30, default=15, description="Period of time a port is in listening and learning state (4 - 30 sec, default = 15).")    
    max_age: int | None = Field(ge=6, le=40, default=20, description="Maximum time before a bridge port expires its configuration BPDU information (6 - 40 sec, default = 20).")    
    max_hops: int | None = Field(ge=1, le=40, default=20, description="Maximum number of hops between the root bridge and the furthest bridge (1- 40, default = 20).")    
    pending_timer: int | None = Field(ge=1, le=15, default=4, description="Pending time (1 - 15 sec, default = 4).")    
    # ========================================================================
    # 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]) -> "StpSettingsModel":
        """
        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__ = [
    "StpSettingsModel",]


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