"""
Pydantic Models for CMDB - firewall/address6_template

Runtime validation models for firewall/address6_template configuration.
Generated from FortiOS schema version unknown.
"""

from __future__ import annotations

from pydantic import BaseModel, Field
from typing import Any, Literal, Optional
from uuid import UUID

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

# ============================================================================
# Child Table Models (sorted deepest-first so nested models are defined before their parents)
# ============================================================================

class Address6TemplateSubnetSegmentValues(BaseModel):
    """
    Child table model for subnet-segment.values.
    
    Subnet segment values.
    """
    
    class Config:
        """Pydantic model configuration."""
        extra = "allow"  # Allow additional fields from API
        str_strip_whitespace = True
        use_enum_values = True  # Use enum values instead of names
    
    name: str = Field(max_length=63, description="Subnet segment value name.")    
    value: str = Field(max_length=35, description="Subnet segment value.")
class Address6TemplateSubnetSegment(BaseModel):
    """
    Child table model for subnet-segment.
    
    IPv6 subnet segments.
    """
    
    class Config:
        """Pydantic model configuration."""
        extra = "allow"  # Allow additional fields from API
        str_strip_whitespace = True
        use_enum_values = True  # Use enum values instead of names
    
    id_: int = Field(ge=0, le=4294967295, default=0, serialization_alias="id", description="Subnet segment ID.")    
    name: str = Field(max_length=63, description="Subnet segment name.")    
    bits: int = Field(ge=1, le=16, default=0, description="Number of bits.")    
    exclusive: Literal["enable", "disable"] = Field(default="disable", description="Enable/disable exclusive value.")    
    values: list[Address6TemplateSubnetSegmentValues] = Field(default_factory=list, description="Subnet segment values.")
# ============================================================================
# Enum Definitions (for fields with 4+ allowed values)
# ============================================================================


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

class Address6TemplateModel(BaseModel):
    """
    Pydantic model for firewall/address6_template configuration.
    
    Configure IPv6 address templates.
    
    Validation Rules:        - name: max_length=63 pattern=        - uuid: pattern=        - ip6: pattern=        - subnet_segment_count: min=1 max=6 pattern=        - subnet_segment: pattern=        - fabric_object: 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="IPv6 address template name.")    
    uuid: str | None = Field(default="00000000-0000-0000-0000-000000000000", description="Universally Unique Identifier (UUID; automatically assigned but can be manually reset).")    
    ip6: str = Field(default="::/0", description="IPv6 address prefix.")    
    subnet_segment_count: int = Field(ge=1, le=6, default=0, description="Number of IPv6 subnet segments.")    
    subnet_segment: list[Address6TemplateSubnetSegment] = Field(default_factory=list, description="IPv6 subnet segments.")    
    fabric_object: Literal["enable", "disable"] | None = Field(default="disable", description="Security Fabric global object setting.")    
    # ========================================================================
    # 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]) -> "Address6TemplateModel":
        """
        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__ = [
    "Address6TemplateModel",    "Address6TemplateSubnetSegment",    "Address6TemplateSubnetSegment.Values",]


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