"""
Pydantic Models for CMDB - router/key_chain

Runtime validation models for router/key_chain 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 Child Table Fields (for fields with 4+ allowed values)
# ============================================================================

class KeyChainKeyAlgorithmEnum(str, Enum):
    """Allowed values for algorithm field in key."""
    MD5 = "md5"
    HMAC_SHA1 = "hmac-sha1"
    HMAC_SHA256 = "hmac-sha256"
    HMAC_SHA384 = "hmac-sha384"
    HMAC_SHA512 = "hmac-sha512"
    CMAC_AES128 = "cmac-aes128"

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

class KeyChainKey(BaseModel):
    """
    Child table model for key.
    
    Configuration method to edit key settings.
    """
    
    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_: str = Field(max_length=10, serialization_alias="id", description="Key ID (0 - 2147483647).")    
    accept_lifetime: str = Field(description="Lifetime of received authentication key (format: hh:mm:ss day month year).")    
    send_lifetime: str = Field(description="Lifetime of sent authentication key (format: hh:mm:ss day month year).")    
    key_string: Any = Field(max_length=60, description="Password for the key (maximum = 64 characters).")    
    algorithm: KeyChainKeyAlgorithmEnum | None = Field(default=KeyChainKeyAlgorithmEnum.MD5, description="Cryptographic algorithm.")
# ============================================================================
# Enum Definitions (for fields with 4+ allowed values)
# ============================================================================


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

class KeyChainModel(BaseModel):
    """
    Pydantic model for router/key_chain configuration.
    
    Configure key-chain.
    
    Validation Rules:        - name: max_length=35 pattern=        - key: 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=35, description="Key-chain name.")    
    key: list[KeyChainKey] = Field(default_factory=list, description="Configuration method to edit key settings.")    
    # ========================================================================
    # 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]) -> "KeyChainModel":
        """
        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__ = [
    "KeyChainModel",    "KeyChainKey",]


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