"""
Pydantic Models for CMDB - switch_controller/snmp_user

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

from __future__ import annotations

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

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

class SnmpUserAuthProtoEnum(str, Enum):
    """Allowed values for auth_proto field."""
    MD5 = "md5"
    SHA1 = "sha1"
    SHA224 = "sha224"
    SHA256 = "sha256"
    SHA384 = "sha384"
    SHA512 = "sha512"

class SnmpUserPrivProtoEnum(str, Enum):
    """Allowed values for priv_proto field."""
    AES128 = "aes128"
    AES192 = "aes192"
    AES192C = "aes192c"
    AES256 = "aes256"
    AES256C = "aes256c"
    DES = "des"


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

class SnmpUserModel(BaseModel):
    """
    Pydantic model for switch_controller/snmp_user configuration.
    
    Configure FortiSwitch SNMP v3 users globally.
    
    Validation Rules:        - name: max_length=32 pattern=        - queries: pattern=        - query_port: min=0 max=65535 pattern=        - security_level: pattern=        - auth_proto: pattern=        - auth_pwd: max_length=128 pattern=        - priv_proto: pattern=        - priv_pwd: max_length=128 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=32, default=None, description="SNMP user name.")    
    queries: Literal["disable", "enable"] | None = Field(default="enable", description="Enable/disable SNMP queries for this user.")    
    query_port: int | None = Field(ge=0, le=65535, default=161, description="SNMPv3 query port (default = 161).")    
    security_level: Literal["no-auth-no-priv", "auth-no-priv", "auth-priv"] | None = Field(default="no-auth-no-priv", description="Security level for message authentication and encryption.")    
    auth_proto: SnmpUserAuthProtoEnum | None = Field(default=SnmpUserAuthProtoEnum.SHA256, description="Authentication protocol.")    
    auth_pwd: Any = Field(max_length=128, description="Password for authentication protocol.")    
    priv_proto: SnmpUserPrivProtoEnum | None = Field(default=SnmpUserPrivProtoEnum.AES128, description="Privacy (encryption) protocol.")    
    priv_pwd: Any = Field(max_length=128, description="Password for privacy (encryption) protocol.")    
    # ========================================================================
    # 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]) -> "SnmpUserModel":
        """
        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__ = [
    "SnmpUserModel",]


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