"""
Pydantic Models for MONITOR - vpn_certificate/csr/generate

Runtime validation models for vpn_certificate/csr/generate configuration.
Generated from FortiOS schema version unknown.
"""

from __future__ import annotations

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

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

class GenerateKeysizeEnum(str, Enum):
    """Allowed values for keysize field."""
    V_1024 = "1024"
    V_1536 = "1536"
    V_2048 = "2048"
    V_4096 = "4096"


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

class GenerateModel(BaseModel):
    """
    Pydantic model for vpn_certificate/csr/generate configuration.
    
    Generate a certificate signing request (CSR) and a private key. The CSR can be retrieved / downloaded from CLI, GUI and REST API.
    
    Validation Rules:        - certname: pattern=        - subject: pattern=        - keytype: pattern=        - keysize: pattern=        - curvename: pattern=        - orgunits: pattern=        - org: pattern=        - city: pattern=        - state: pattern=        - countrycode: pattern=        - email: pattern=        - subject_alt_name: pattern=        - password: pattern=        - scep_url: pattern=        - scep_password: pattern=        - scope: 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
    # ========================================================================
    
    certname: str = Field()    
    subject: str = Field()    
    keytype: Literal["rsa", "ec"] = Field()    
    keysize: GenerateKeysizeEnum | None = Field(default=None)    
    curvename: Literal["secp256r1", "secp384r1", "secp521r1"] | None = Field(default=None)    
    orgunits: Any = Field(default=None)    
    org: str | None = Field(default=None)    
    city: str | None = Field(default=None)    
    state: str | None = Field(default=None)    
    countrycode: str | None = Field(default=None)    
    email: str | None = Field(default=None)    
    subject_alt_name: str | None = Field(default=None)    
    password: str | None = Field(default=None)    
    scep_url: str | None = Field(default=None)    
    scep_password: str | None = Field(default=None)    
    scope: Literal["vdom", "global"] | None = Field(default=None)    
    # ========================================================================
    # 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]) -> "GenerateModel":
        """
        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__ = [
    "GenerateModel",]


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