/*
 * Hetzner Cloud API
 *
 * Copied from the official API documentation for the Public Hetzner Cloud.
 *
 * The version of the OpenAPI document: 4b3f595
 *
 * Generated by: https://openapi-generator.tech
 */

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

/// Action : Actions show the results and progress of asynchronous requests to the API.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Action {
    /// Command executed in the Action.
    #[serde(rename = "command")]
    pub command: String,
    /// Error message for the Action if an error occurred, otherwise null.
    #[serde(rename = "error", deserialize_with = "Option::deserialize")]
    pub error: Option<Box<models::Error>>,
    /// Point in time when the Action was finished (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format). Only set if the Action is finished otherwise null.
    #[serde(rename = "finished", deserialize_with = "Option::deserialize")]
    pub finished: Option<String>,
    /// ID of the Action.
    #[serde(rename = "id")]
    pub id: i64,
    /// Progress of the Action in percent.
    #[serde(rename = "progress")]
    pub progress: i32,
    /// Resources the Action relates to.
    #[serde(rename = "resources")]
    pub resources: Vec<models::Resource>,
    /// Point in time when the Action was started (in [RFC3339](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format).
    #[serde(rename = "started")]
    pub started: String,
    /// Status of the Action.
    #[serde(rename = "status")]
    pub status: Status,
}

impl Action {
    /// Actions show the results and progress of asynchronous requests to the API.
    pub fn new(
        command: String,
        error: Option<models::Error>,
        finished: Option<String>,
        id: i64,
        progress: i32,
        resources: Vec<models::Resource>,
        started: String,
        status: Status,
    ) -> Action {
        Action {
            command,
            error: error.map(Box::new),
            finished,
            id,
            progress,
            resources,
            started,
            status,
        }
    }
}
/// Status of the Action.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
    #[serde(rename = "error")]
    Error,
    #[serde(rename = "running")]
    Running,
    #[serde(rename = "success")]
    Success,
}

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