"""
Pydantic Models for CMDB - switch_controller/traffic_policy

Runtime validation models for switch_controller/traffic_policy 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 TrafficPolicyModel(BaseModel):
    """
    Pydantic model for switch_controller/traffic_policy configuration.
    
    Configure FortiSwitch traffic policy.
    
    Validation Rules:        - name: max_length=63 pattern=        - description: max_length=63 pattern=        - policer_status: pattern=        - guaranteed_bandwidth: min=0 max=524287000 pattern=        - guaranteed_burst: min=0 max=4294967295 pattern=        - maximum_burst: min=0 max=4294967295 pattern=        - type_: pattern=        - cos_queue: min=0 max=7 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 = Field(max_length=63, description="Traffic policy name.")    
    description: str | None = Field(max_length=63, default=None, description="Description of the traffic policy.")    
    policer_status: Literal["enable", "disable"] | None = Field(default="enable", description="Enable/disable policer config on the traffic policy.")    
    guaranteed_bandwidth: int | None = Field(ge=0, le=524287000, default=10000, description="Guaranteed bandwidth in kbps (max value = 524287000).")    
    guaranteed_burst: int | None = Field(ge=0, le=4294967295, default=45000, description="Guaranteed burst size in bytes (max value = 4294967295).")    
    maximum_burst: int | None = Field(ge=0, le=4294967295, default=67500, description="Maximum burst size in bytes (max value = 4294967295).")    
    type_: Literal["ingress", "egress"] | None = Field(default="ingress", serialization_alias="type", description="Configure type of policy(ingress/egress).")    
    cos_queue: int | None = Field(ge=0, le=7, default=None, description="COS queue(0 - 7), or unset to disable.")    
    # ========================================================================
    # 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]) -> "TrafficPolicyModel":
        """
        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__ = [
    "TrafficPolicyModel",]


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