/*
 * This is an auto-generated file.
 * Any manual changes may be overwritten without notice!
 */

use derive_builder::Builder;
use serde::{Deserialize, Serialize};

/// TaskState tracks the current state of a task and events that caused state
/// transitions.
///
/// This struct was generated based on the Go types of the official Nomad API.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Builder)]
pub struct TaskState {
    #[serde(rename = "LastRestart")]
    pub last_restart: chrono::DateTime<chrono::Utc>,

    #[serde(rename = "StartedAt")]
    pub started_at: chrono::DateTime<chrono::Utc>,

    #[serde(rename = "FinishedAt")]
    pub finished_at: chrono::DateTime<chrono::Utc>,

    #[serde(
        rename = "Events",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub events: Vec<super::TaskEvent>,

    /// Experimental -  TaskHandle is based on drivers.TaskHandle and used
    /// by remote task drivers to migrate task handles between allocations.
    #[serde(rename = "TaskHandle", skip_serializing_if = "Option::is_none")]
    pub task_handle: Option<super::TaskHandle>,

    #[serde(rename = "State")]
    pub state: String,

    #[serde(rename = "Failed")]
    pub failed: bool,

    #[serde(rename = "Restarts")]
    pub restarts: u64,
}
