"""
Pydantic Models for CMDB - switch_controller/security_policy/local_access

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

from __future__ import annotations

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

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

class LocalAccessMgmtAllowaccessEnum(str, Enum):
    """Allowed values for mgmt_allowaccess field."""
    HTTPS = "https"
    PING = "ping"
    SSH = "ssh"
    SNMP = "snmp"
    HTTP = "http"
    TELNET = "telnet"
    RADIUS_ACCT = "radius-acct"

class LocalAccessInternalAllowaccessEnum(str, Enum):
    """Allowed values for internal_allowaccess field."""
    HTTPS = "https"
    PING = "ping"
    SSH = "ssh"
    SNMP = "snmp"
    HTTP = "http"
    TELNET = "telnet"
    RADIUS_ACCT = "radius-acct"


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

class LocalAccessModel(BaseModel):
    """
    Pydantic model for switch_controller/security_policy/local_access configuration.
    
    Configure allowaccess list for mgmt and internal interfaces on managed FortiSwitch units.
    
    Validation Rules:        - name: max_length=31 pattern=        - mgmt_allowaccess: pattern=        - internal_allowaccess: 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="Policy name.")    
    mgmt_allowaccess: list[LocalAccessMgmtAllowaccessEnum] = Field(default_factory=list, description="Allowed access on the switch management interface.")    
    internal_allowaccess: list[LocalAccessInternalAllowaccessEnum] = Field(default_factory=list, description="Allowed access on the switch internal interface.")    
    # ========================================================================
    # 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]) -> "LocalAccessModel":
        """
        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__ = [
    "LocalAccessModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.2
# Generated: 2026-01-21T16:24:00.036475Z
# ============================================================================