"""
Pydantic Models for CMDB - system/auto_script

Runtime validation models for system/auto_script configuration.
Generated from FortiOS schema version unknown.
"""

from __future__ import annotations

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

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


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

class AutoScriptModel(BaseModel):
    """
    Pydantic model for system/auto_script configuration.
    
    Configure auto script.
    
    Validation Rules:        - name: max_length=35 pattern=        - interval: min=0 max=31557600 pattern=        - repeat: min=0 max=65535 pattern=        - start: pattern=        - script: max_length=1023 pattern=        - output_size: min=10 max=1024 pattern=        - timeout: min=0 max=300 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="Auto script name.")    
    interval: int | None = Field(ge=0, le=31557600, default=0, description="Repeat interval in seconds.")    
    repeat: int | None = Field(ge=0, le=65535, default=1, description="Number of times to repeat this script (0 = infinite).")    
    start: Literal["manual", "auto"] | None = Field(default="manual", description="Script starting mode.")    
    script: str | None = Field(max_length=1023, default=None, description="List of FortiOS CLI commands to repeat.")    
    output_size: int | None = Field(ge=10, le=1024, default=10, description="Number of megabytes to limit script output to (10 - 1024, default = 10).")    
    timeout: int | None = Field(ge=0, le=300, default=0, description="Maximum running time for this script in seconds (0 = no timeout).")    
    # ========================================================================
    # 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]) -> "AutoScriptModel":
        """
        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__ = [
    "AutoScriptModel",]


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