"""
Pydantic Models for CMDB - firewall/internet_service_append

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

from __future__ import annotations

from pydantic import BaseModel, Field, field_validator
from typing import Any, Literal, Optional

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


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

class InternetServiceAppendModel(BaseModel):
    """
    Pydantic model for firewall/internet_service_append configuration.
    
    Configure additional port mappings for Internet Services.
    
    Validation Rules:        - addr_mode: pattern=        - match_port: min=0 max=65535 pattern=        - append_port: min=0 max=65535 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
    # ========================================================================
    
    addr_mode: Literal["ipv4", "ipv6", "both"] | None = Field(default="ipv4", description="Address mode (IPv4 or IPv6).")    
    match_port: int | None = Field(ge=0, le=65535, default=0, description="Matching TCP/UDP/SCTP destination port (0 to 65535, 0 means any port).")    
    append_port: int | None = Field(ge=0, le=65535, default=0, description="Appending TCP/UDP/SCTP destination port (1 to 65535).")    
    # ========================================================================
    # 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]) -> "InternetServiceAppendModel":
        """
        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__ = [
    "InternetServiceAppendModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-17T04:31:41.958831Z
# ============================================================================