"""
Pydantic Models for CMDB - switch_controller/initial_config/template

Runtime validation models for switch_controller/initial_config/template 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 TemplateAllowaccessEnum(str, Enum):
    """Allowed values for allowaccess field."""
    PING = "ping"
    HTTPS = "https"
    SSH = "ssh"
    SNMP = "snmp"
    HTTP = "http"
    TELNET = "telnet"
    FGFM = "fgfm"
    RADIUS_ACCT = "radius-acct"
    PROBE_RESPONSE = "probe-response"
    FABRIC = "fabric"
    FTM = "ftm"


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

class TemplateModel(BaseModel):
    """
    Pydantic model for switch_controller/initial_config/template configuration.
    
    Configure template for auto-generated VLANs.
    
    Validation Rules:        - name: max_length=63 pattern=        - vlanid: min=1 max=4094 pattern=        - ip: pattern=        - allowaccess: pattern=        - auto_ip: pattern=        - dhcp_server: 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="Initial config template name.")    
    vlanid: int = Field(ge=1, le=4094, default=0, description="Unique VLAN ID.")    
    ip: Any = Field(default="0.0.0.0 0.0.0.0", description="Interface IPv4 address and subnet mask.")    
    allowaccess: list[TemplateAllowaccessEnum] = Field(default_factory=list, description="Permitted types of management access to this interface.")    
    auto_ip: Literal["enable", "disable"] | None = Field(default="enable", description="Automatically allocate interface address and subnet block.")    
    dhcp_server: Literal["enable", "disable"] | None = Field(default="disable", description="Enable/disable a DHCP server on this 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]) -> "TemplateModel":
        """
        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__ = [
    "TemplateModel",]


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