/*
 * 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};

/// WebhookSecretCreatedResponse : Response returned exactly once when a webhook is created or its secret is rotated. The raw `secret` value is not retrievable afterwards.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct WebhookSecretCreatedResponse {
    #[serde(rename = "created_at")]
    pub created_at: String,
    /// Pinned event payload version (e.g. \"2026-04-01\"). Determines the shape of the rendered payload and the value sent in the `X-ArtifactKeeper-Event-Version` header.
    #[serde(rename = "event_schema_version")]
    pub event_schema_version: String,
    #[serde(rename = "events")]
    pub events: Vec<String>,
    #[serde(rename = "headers", skip_serializing_if = "Option::is_none")]
    pub headers: Option<serde_json::Value>,
    #[serde(rename = "id")]
    pub id: uuid::Uuid,
    #[serde(rename = "is_enabled")]
    pub is_enabled: bool,
    #[serde(rename = "last_triggered_at", skip_serializing_if = "Option::is_none")]
    pub last_triggered_at: Option<String>,
    #[serde(rename = "name")]
    pub name: String,
    #[serde(rename = "payload_template")]
    pub payload_template: models::PayloadTemplate,
    #[serde(rename = "repository_id", skip_serializing_if = "Option::is_none")]
    pub repository_id: Option<uuid::Uuid>,
    /// Short non-reversible identifier for the current signing secret (`whsec_...abcd`), suitable for display in operator UIs. The raw secret is never returned by GET or LIST.
    #[serde(rename = "secret_digest", skip_serializing_if = "Option::is_none")]
    pub secret_digest: Option<String>,
    /// True while a previous secret is still accepted by the retry path during a rotation overlap window.
    #[serde(rename = "secret_rotation_active", skip_serializing_if = "Option::is_none")]
    pub secret_rotation_active: Option<bool>,
    #[serde(rename = "url")]
    pub url: String,
    /// Raw signing secret. Display this to the operator immediately and instruct them to record it; the server retains only the encrypted form and a short digest.  Absent when the webhook was created without a signing secret. This happens when no secret was supplied and the deployment has no `AK_WEBHOOK_SECRET_KEY` configured: rather than fail the create with a 500, the webhook is stored unsigned and deliveries omit the signature header. Configure the key and rotate the secret later to enable signing.
    #[serde(rename = "secret", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
    pub secret: Option<Option<String>>,
}

impl WebhookSecretCreatedResponse {
    /// Response returned exactly once when a webhook is created or its secret is rotated. The raw `secret` value is not retrievable afterwards.
    pub fn new(created_at: String, event_schema_version: String, events: Vec<String>, id: uuid::Uuid, is_enabled: bool, name: String, payload_template: models::PayloadTemplate, url: String) -> WebhookSecretCreatedResponse {
        WebhookSecretCreatedResponse {
            created_at,
            event_schema_version,
            events,
            headers: None,
            id,
            is_enabled,
            last_triggered_at: None,
            name,
            payload_template,
            repository_id: None,
            secret_digest: None,
            secret_rotation_active: None,
            url,
            secret: None,
        }
    }
}

