"""
Pydantic Models for CMDB - firewall/internet_service

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

Example Usage:
    >>> from hfortix_fortios.models.cmdb.firewall.internet_service import 
    >>>
    >>> # Create with validation
    >>> obj = (
    ...     id=1,
    ...     name="example",
    ... )
    >>>
    >>> # Validation happens automatically
    >>> # ValidationError raised if constraints violated
"""

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 InternetServiceModel(BaseModel):
    """
    Pydantic model for firewall/internet_service configuration.
    
    Show Internet Service application.
    
    Validation Rules:        - id: min=0 max=4294967295 pattern=        - name: max_length=63 pattern=        - icon_id: min=0 max=4294967295 pattern=        - direction: pattern=        - database: pattern=        - ip_range_number: min=0 max=4294967295 pattern=        - extra_ip_range_number: min=0 max=4294967295 pattern=        - ip_number: min=0 max=4294967295 pattern=        - ip6_range_number: min=0 max=4294967295 pattern=        - extra_ip6_range_number: min=0 max=4294967295 pattern=        - singularity: min=0 max=65535 pattern=        - obsolete: min=0 max=255 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
    # ========================================================================
    
    id: int | None = Field(ge=0, le=4294967295, default=0, description="Internet Service ID.")    
    name: str | None = Field(max_length=63, default="", description="Internet Service name.")    
    icon_id: int | None = Field(ge=0, le=4294967295, default=0, description="Icon ID of Internet Service.")    
    direction: Literal["src", "dst", "both"] | None = Field(default="both", description="How this service may be used in a firewall policy (source, destination or both).")    
    database: Literal["isdb", "irdb"] | None = Field(default="isdb", description="Database name this Internet Service belongs to.")    
    ip_range_number: int | None = Field(ge=0, le=4294967295, default=0, description="Number of IPv4 ranges.")    
    extra_ip_range_number: int | None = Field(ge=0, le=4294967295, default=0, description="Extra number of IPv4 ranges.")    
    ip_number: int | None = Field(ge=0, le=4294967295, default=0, description="Total number of IPv4 addresses.")    
    ip6_range_number: int | None = Field(ge=0, le=4294967295, default=0, description="Number of IPv6 ranges.")    
    extra_ip6_range_number: int | None = Field(ge=0, le=4294967295, default=0, description="Extra number of IPv6 ranges.")    
    singularity: int | None = Field(ge=0, le=65535, default=0, description="Singular level of the Internet Service.")    
    obsolete: int | None = Field(ge=0, le=255, default=0, description="Indicates whether the Internet Service can be used.")    
    # ========================================================================
    # 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]) -> "":
        """
        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__ = [
    "InternetServiceModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-09T09:47:41.995145Z
# ============================================================================