/*
 * 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.2.4
 * 
 * Generated by: https://openapi-generator.tech
 */

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

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct CreateWebhookRequest {
    /// Pinned event payload version. Defaults to \"2026-04-01\" when omitted. Must match a value in `SUPPORTED_EVENT_VERSIONS` or the request is rejected with HTTP 422.
    #[serde(rename = "event_schema_version", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub event_schema_version: Option<Option<String>>,
    #[serde(rename = "events")]
    pub events: Vec<String>,
    #[serde(rename = "headers", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub headers: Option<Option<serde_json::Value>>,
    #[serde(rename = "name")]
    pub name: String,
    /// Payload layout for the target platform (default: generic).
    #[serde(rename = "payload_template", skip_serializing_if = "Option::is_none")]
    pub payload_template: Option<models::PayloadTemplate>,
    #[serde(rename = "repository_id", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub repository_id: Option<Option<uuid::Uuid>>,
    /// Optional caller-supplied secret. When omitted the server generates a fresh `whsec_*` secret. Either way the raw value is returned in the 201 response body exactly once and is unrecoverable thereafter.
    #[serde(rename = "secret", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub secret: Option<Option<String>>,
    #[serde(rename = "url")]
    pub url: String,
}

impl CreateWebhookRequest {
    pub fn new(events: Vec<String>, name: String, url: String) -> CreateWebhookRequest {
        CreateWebhookRequest {
            event_schema_version: None,
            events,
            headers: None,
            name,
            payload_template: None,
            repository_id: None,
            secret: None,
            url,
        }
    }
}

