/*
 * Zernio API
 *
 * API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
 *
 * The version of the OpenAPI document: 1.0.4
 * Contact: support@zernio.com
 * Generated by: https://openapi-generator.tech
 */

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

/// WebhookLog : A single webhook delivery attempt recorded by Zernio (30-day retention).
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct WebhookLog {
    /// ID of the account owner the webhook belongs to
    #[serde(rename = "userId", skip_serializing_if = "Option::is_none")]
    pub user_id: Option<String>,
    /// ID of the webhook configuration that produced this delivery
    #[serde(rename = "webhookId", skip_serializing_if = "Option::is_none")]
    pub webhook_id: Option<String>,
    /// Name of the webhook configuration at delivery time
    #[serde(rename = "webhookName", skip_serializing_if = "Option::is_none")]
    pub webhook_name: Option<String>,
    /// Stable webhook event ID (correlates to the delivered payload)
    #[serde(rename = "eventId", skip_serializing_if = "Option::is_none")]
    pub event_id: Option<String>,
    /// Event type that triggered the delivery (e.g. post.published)
    #[serde(rename = "event", skip_serializing_if = "Option::is_none")]
    pub event: Option<String>,
    /// Destination URL the webhook was delivered to
    #[serde(rename = "url", skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
    /// Delivery outcome
    #[serde(rename = "status", skip_serializing_if = "Option::is_none")]
    pub status: Option<Status>,
    /// HTTP status code returned by the destination endpoint
    #[serde(rename = "statusCode", skip_serializing_if = "Option::is_none")]
    pub status_code: Option<i32>,
    /// The JSON payload sent to the destination endpoint
    #[serde(rename = "requestPayload", skip_serializing_if = "Option::is_none")]
    pub request_payload: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Response body returned by the destination endpoint
    #[serde(rename = "responseBody", skip_serializing_if = "Option::is_none")]
    pub response_body: Option<String>,
    /// Error message when delivery failed
    #[serde(rename = "errorMessage", skip_serializing_if = "Option::is_none")]
    pub error_message: Option<String>,
    /// Delivery attempt number (increments on retries)
    #[serde(rename = "attemptNumber", skip_serializing_if = "Option::is_none")]
    pub attempt_number: Option<i32>,
    /// Time taken by the destination endpoint to respond, in milliseconds
    #[serde(rename = "responseTime", skip_serializing_if = "Option::is_none")]
    pub response_time: Option<i32>,
    /// Timestamp the delivery was attempted
    #[serde(rename = "createdAt", skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,
}

impl WebhookLog {
    /// A single webhook delivery attempt recorded by Zernio (30-day retention).
    pub fn new() -> WebhookLog {
        WebhookLog {
            user_id: None,
            webhook_id: None,
            webhook_name: None,
            event_id: None,
            event: None,
            url: None,
            status: None,
            status_code: None,
            request_payload: None,
            response_body: None,
            error_message: None,
            attempt_number: None,
            response_time: None,
            created_at: None,
        }
    }
}
/// Delivery outcome
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "success")]
    Success,
    #[serde(rename = "failed")]
    Failed,
}

impl Default for Status {
    fn default() -> Status {
        Self::Success
    }
}
