"""
Pydantic Models for CMDB - system/storage

Runtime validation models for system/storage 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 StorageModel(BaseModel):
    """
    Pydantic model for system/storage configuration.
    
    Configure logical storage.
    
    Validation Rules:        - name: max_length=35 pattern=        - status: pattern=        - media_status: pattern=        - order: min=0 max=255 pattern=        - partition: max_length=16 pattern=        - device: max_length=19 pattern=        - size: min=0 max=4294967295 pattern=        - usage: pattern=        - wanopt_mode: 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="default_n", description="Storage name.")    
    status: Literal["enable", "disable"] | None = Field(default="enable", description="Enable/disable storage.")    
    media_status: Literal["enable", "disable", "fail"] | None = Field(default="disable", description="The physical status of current media.")    
    order: int | None = Field(ge=0, le=255, default=0, description="Set storage order.")    
    partition: str | None = Field(max_length=16, default="<unknown>", description="Label of underlying partition.")    
    device: str | None = Field(max_length=19, default="?", description="Partition device.")    
    size: int | None = Field(ge=0, le=4294967295, default=0, description="Partition size.")    
    usage: Literal["log", "wanopt"] | None = Field(default="log", description="Use hard disk for logging or WAN Optimization (default = log).")    
    wanopt_mode: Literal["mix", "wanopt", "webcache"] | None = Field(default="mix", description="WAN Optimization mode (default = mix).")    
    # ========================================================================
    # 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]) -> "StorageModel":
        """
        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__ = [
    "StorageModel",]


# ============================================================================
# Generated by hfortix generator v0.6.0
# Schema: 1.7.0
# Generated: 2026-01-17T17:56:13.302517Z
# ============================================================================