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

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

/// Task is a single process in a task group.
///
/// This struct was generated based on the Go types of the official Nomad API.
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, Builder)]
pub struct Task {
    #[serde(rename = "logs", skip_serializing_if = "Option::is_none")]
    pub log_config: Option<super::LogConfig>,

    #[serde(rename = "DispatchPayload", skip_serializing_if = "Option::is_none")]
    pub dispatch_payload: Option<super::DispatchPayloadConfig>,

    #[serde(rename = "csi_plugin", skip_serializing_if = "Option::is_none")]
    pub csi_plugin_config: Option<super::TaskCsiPluginConfig>,

    #[serde(rename = "Kind")]
    pub kind: String,

    #[serde(rename = "Driver")]
    pub driver: String,

    #[serde(rename = "User")]
    pub user: String,

    #[serde(rename = "Resources", skip_serializing_if = "Option::is_none")]
    pub resources: Option<super::Resources>,

    #[serde(rename = "Schedule", skip_serializing_if = "Option::is_none")]
    pub schedule: Option<super::TaskSchedule>,

    #[serde(rename = "Lifecycle", skip_serializing_if = "Option::is_none")]
    pub lifecycle: Option<super::TaskLifecycle>,

    #[serde(
        rename = "shutdown_delay",
        skip_serializing_if = "Option::is_none",
        serialize_with = "crate::serialize_duration_option",
        deserialize_with = "crate::deserialize_duration_option",
        default
    )]
    pub shutdown_delay: Option<chrono::TimeDelta>,

    #[serde(
        rename = "Actions",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub actions: Vec<super::Action>,

    #[serde(
        rename = "Constraints",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub constraints: Vec<super::Constraint>,

    #[serde(
        rename = "Artifacts",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub artifacts: Vec<super::TaskArtifact>,

    #[serde(rename = "RestartPolicy", skip_serializing_if = "Option::is_none")]
    pub restart_policy: Option<super::RestartPolicy>,

    #[serde(
        rename = "kill_timeout",
        skip_serializing_if = "Option::is_none",
        serialize_with = "crate::serialize_duration_option",
        deserialize_with = "crate::deserialize_duration_option",
        default
    )]
    pub kill_timeout: Option<chrono::TimeDelta>,

    /// Identity is the default Nomad Workload Identity and will be added to
    /// Identities with the name "default"
    #[serde(rename = "Identity", skip_serializing_if = "Option::is_none")]
    pub identity: Option<super::WorkloadIdentity>,

    #[serde(rename = "Config")]
    pub config: std::collections::HashMap<String, serde_json::Value>,

    #[serde(
        rename = "Templates",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub templates: Vec<super::Template>,

    #[serde(
        rename = "ScalingPolicies",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub scaling_policies: Vec<super::ScalingPolicy>,

    #[serde(
        rename = "Services",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub services: Vec<super::Service>,

    #[serde(rename = "kill_signal", skip_serializing_if = "Option::is_none")]
    pub kill_signal: Option<String>,

    /// Workload Identities
    #[serde(
        rename = "Identities",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub identities: Vec<super::WorkloadIdentity>,

    #[serde(rename = "Env")]
    pub env: std::collections::HashMap<String, String>,

    #[serde(
        rename = "VolumeMounts",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub volume_mounts: Vec<super::VolumeMount>,

    #[serde(rename = "Vault", skip_serializing_if = "Option::is_none")]
    pub vault: Option<super::Vault>,

    #[serde(rename = "Consul", skip_serializing_if = "Option::is_none")]
    pub consul: Option<super::Consul>,

    #[serde(rename = "Leader")]
    pub leader: bool,

    #[serde(rename = "Name")]
    pub name: String,

    #[serde(
        rename = "Affinities",
        deserialize_with = "crate::deserialize_null_as_default"
    )]
    pub affinities: Vec<super::Affinity>,

    #[serde(rename = "Meta")]
    pub meta: std::collections::HashMap<String, String>,
}
