"""
Pydantic Models for CMDB - firewall/ssh/host_key

Runtime validation models for firewall/ssh/host_key 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 HostKeyTypeEnum(str, Enum):
    """Allowed values for type_ field."""
    RSA = "RSA"
    DSA = "DSA"
    ECDSA = "ECDSA"
    ED25519 = "ED25519"
    RSA_CA = "RSA-CA"
    DSA_CA = "DSA-CA"
    ECDSA_CA = "ECDSA-CA"
    ED25519_CA = "ED25519-CA"


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

class HostKeyModel(BaseModel):
    """
    Pydantic model for firewall/ssh/host_key configuration.
    
    SSH proxy host public keys.
    
    Validation Rules:        - name: max_length=35 pattern=        - status: pattern=        - type_: pattern=        - nid: pattern=        - usage: pattern=        - ip: pattern=        - port: min=0 max=4294967295 pattern=        - hostname: max_length=255 pattern=        - public_key: max_length=32768 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=35, default=None, description="SSH public key name.")    
    status: Literal["trusted", "revoked"] | None = Field(default="trusted", description="Set the trust status of the public key.")    
    type_: HostKeyTypeEnum | None = Field(default=HostKeyTypeEnum.RSA, serialization_alias="type", description="Set the type of the public key.")    
    nid: Literal["256", "384", "521"] | None = Field(default="256", description="Set the nid of the ECDSA key.")    
    usage: Literal["transparent-proxy", "access-proxy"] | None = Field(default="transparent-proxy", description="Usage for this public key.")    
    ip: str | None = Field(default="0.0.0.0", description="IP address of the SSH server.")    
    port: int | None = Field(ge=0, le=4294967295, default=22, description="Port of the SSH server.")    
    hostname: str | None = Field(max_length=255, default=None, description="Hostname of the SSH server to match SSH certificate principals.")    
    public_key: str | None = Field(max_length=32768, default=None, description="SSH public key.")    
    # ========================================================================
    # 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]) -> "HostKeyModel":
        """
        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__ = [
    "HostKeyModel",]


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