"""
Pydantic Models for CMDB - ips/custom

Runtime validation models for ips/custom 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 CustomModel(BaseModel):
    """
    Pydantic model for ips/custom configuration.
    
    Configure IPS custom signature.
    
    Validation Rules:        - tag: max_length=63 pattern=        - signature: max_length=4095 pattern=        - rule_id: min=0 max=4294967295 pattern=        - severity: pattern=        - location: pattern=        - os: pattern=        - application: pattern=        - protocol: pattern=        - status: pattern=        - log: pattern=        - log_packet: pattern=        - action: pattern=        - comment: max_length=63 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
    # ========================================================================
    
    tag: str | None = Field(max_length=63, default="", description="Signature tag.")    
    signature: str | None = Field(max_length=4095, default=None, description="Custom signature enclosed in single quotes.")    
    rule_id: int | None = Field(ge=0, le=4294967295, default=0, description="Signature ID.")    
    severity: str | None = Field(default="", description="Relative severity of the signature, from info to critical. Log messages generated by the signature include the severity.")    
    location: list[Location] = Field(default="", description="Protect client or server traffic.")    
    os: list[Os] = Field(default="", description="Operating system(s) that the signature protects. Blank for all operating systems.")    
    application: list[Application] = Field(default="", description="Applications to be protected. Blank for all applications.")    
    protocol: str | None = Field(default="", description="Protocol(s) that the signature scans. Blank for all protocols.")    
    status: Literal["disable", "enable"] | None = Field(default="enable", description="Enable/disable this signature.")    
    log: Literal["disable", "enable"] | None = Field(default="enable", description="Enable/disable logging.")    
    log_packet: Literal["disable", "enable"] | None = Field(default="disable", description="Enable/disable packet logging.")    
    action: Literal["pass", "block"] | None = Field(default="pass", description="Default action (pass or block) for this signature.")    
    comment: str | None = Field(max_length=63, default="", description="Comment.")    
    # ========================================================================
    # 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]) -> "CustomModel":
        """
        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__ = [
    "CustomModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-17T02:10:49.718810Z
# ============================================================================