/*
 * Artifact Keeper API
 *
 * Enterprise artifact registry supporting 45+ package formats.  ## Authentication  The JSON management API under `/api/v1/_*` accepts **API tokens only as `Authorization: Bearer <token>`**. This is the canonical scheme for programmatic access; JWTs issued by the login flow also use `Bearer`. HTTP Basic credentials on `/api/v1/_*` are validated *only* as a real `username:password` login — the password half is **not** retried as an API token. A request to `/api/v1/_*` that sends an API token in the password field of Basic auth therefore returns `401 AUTH_ERROR`; switch to `Authorization: Bearer <token>`.  Format (package-manager) endpoints such as `/v2/_*` (OCI), `/incus/_*`, `/debian/_*`, and the language registries are intentionally more permissive for client compatibility: in addition to Bearer, they accept HTTP **Basic** auth with the API token supplied in the *password* field (any username), matching the `pip` netrc / Artifactory-style `token:<api_token>` convention used by package managers that cannot send a Bearer header. This Basic-with-token fallback applies to format endpoints only, never to `/api/v1/_*`.
 *
 * The version of the OpenAPI document: 1.3.0
 * 
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// FormatHandlerResponse : Format handler response with additional computed fields.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct FormatHandlerResponse {
    /// Plugin capabilities if this is a WASM handler
    #[serde(rename = "capabilities", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub capabilities: Option<Option<serde_json::Value>>,
    #[serde(rename = "created_at")]
    pub created_at: String,
    #[serde(rename = "description", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub description: Option<Option<String>>,
    #[serde(rename = "display_name")]
    pub display_name: String,
    #[serde(rename = "extensions")]
    pub extensions: Vec<String>,
    #[serde(rename = "format_key")]
    pub format_key: String,
    #[serde(rename = "handler_type")]
    pub handler_type: models::FormatHandlerType,
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    #[serde(rename = "is_enabled")]
    pub is_enabled: bool,
    #[serde(rename = "plugin_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub plugin_id: Option<Option<uuid::Uuid>>,
    #[serde(rename = "priority")]
    pub priority: i32,
    /// Number of repositories using this format (computed)
    #[serde(rename = "repository_count", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub repository_count: Option<Option<i64>>,
    #[serde(rename = "updated_at")]
    pub updated_at: String,
}

impl FormatHandlerResponse {
    /// Format handler response with additional computed fields.
    pub fn new(created_at: String, display_name: String, extensions: Vec<String>, format_key: String, handler_type: models::FormatHandlerType, id: uuid::Uuid, is_enabled: bool, priority: i32, updated_at: String) -> FormatHandlerResponse {
        FormatHandlerResponse {
            capabilities: None,
            created_at,
            description: None,
            display_name,
            extensions,
            format_key,
            handler_type,
            id,
            is_enabled,
            plugin_id: None,
            priority,
            repository_count: None,
            updated_at,
        }
    }
}

