// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -f scheduledbackups.yml --schema=derived --docs -b --derive=Default --derive=PartialEq --smart-derive-elision
// kopium version: 0.21.2

#[allow(unused_imports)]
mod prelude {
    pub use kube_derive::CustomResource;
    #[cfg(feature = "schemars")]
    pub use schemars::JsonSchema;
    pub use serde::{Deserialize, Serialize};
    pub use std::collections::BTreeMap;
    #[cfg(feature = "builder")]
    pub use typed_builder::TypedBuilder;
}
use self::prelude::*;

/// Specification of the desired behavior of the ScheduledBackup.
/// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
#[derive(CustomResource, Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
#[cfg_attr(not(feature = "schemars"), kube(schema = "disabled"))]
#[kube(
    group = "postgresql.cnpg.io",
    version = "v1",
    kind = "ScheduledBackup",
    plural = "scheduledbackups"
)]
#[kube(namespaced)]
#[kube(status = "ScheduledBackupStatus")]
#[kube(derive = "Default")]
#[kube(derive = "PartialEq")]
pub struct ScheduledBackupSpec {
    /// Indicates which ownerReference should be put inside the created backup resources.<br />
    /// - none: no owner reference for created backup objects (same behavior as before the field was introduced)<br />
    /// - self: sets the Scheduled backup object as owner of the backup<br />
    /// - cluster: set the cluster as owner of the backup<br />
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "backupOwnerReference"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub backup_owner_reference: Option<ScheduledBackupBackupOwnerReference>,
    /// The cluster to backup
    pub cluster: ScheduledBackupCluster,
    /// If the first backup has to be immediately start after creation or not
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub immediate: Option<bool>,
    /// The backup method to be used, possible options are `barmanObjectStore`,
    /// `volumeSnapshot` or `plugin`. Defaults to: `barmanObjectStore`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub method: Option<ScheduledBackupMethod>,
    /// Whether the default type of backup with volume snapshots is
    /// online/hot (`true`, default) or offline/cold (`false`)
    /// Overrides the default setting specified in the cluster field '.spec.backup.volumeSnapshot.online'
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub online: Option<bool>,
    /// Configuration parameters to control the online/hot backup with volume snapshots
    /// Overrides the default settings specified in the cluster '.backup.volumeSnapshot.onlineConfiguration' stanza
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "onlineConfiguration"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub online_configuration: Option<ScheduledBackupOnlineConfiguration>,
    /// Configuration parameters passed to the plugin managing this backup
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "pluginConfiguration"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub plugin_configuration: Option<ScheduledBackupPluginConfiguration>,
    /// The schedule does not follow the same format used in Kubernetes CronJobs
    /// as it includes an additional seconds specifier,
    /// see https://pkg.go.dev/github.com/robfig/cron#hdr-CRON_Expression_Format
    pub schedule: String,
    /// If this backup is suspended or not
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub suspend: Option<bool>,
    /// The policy to decide which instance should perform this backup. If empty,
    /// it defaults to `cluster.spec.backup.target`.
    /// Available options are empty string, `primary` and `prefer-standby`.
    /// `primary` to have backups run always on primary instances,
    /// `prefer-standby` to have backups run preferably on the most updated
    /// standby, if available.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub target: Option<ScheduledBackupTarget>,
}

/// Specification of the desired behavior of the ScheduledBackup.
/// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum ScheduledBackupBackupOwnerReference {
    #[serde(rename = "none")]
    None,
    #[serde(rename = "self")]
    r#_Self,
    #[serde(rename = "cluster")]
    Cluster,
}

/// The cluster to backup
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ScheduledBackupCluster {
    /// Name of the referent.
    pub name: String,
}

/// Specification of the desired behavior of the ScheduledBackup.
/// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum ScheduledBackupMethod {
    #[serde(rename = "barmanObjectStore")]
    BarmanObjectStore,
    #[serde(rename = "volumeSnapshot")]
    VolumeSnapshot,
    #[serde(rename = "plugin")]
    Plugin,
}

/// Configuration parameters to control the online/hot backup with volume snapshots
/// Overrides the default settings specified in the cluster '.backup.volumeSnapshot.onlineConfiguration' stanza
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ScheduledBackupOnlineConfiguration {
    /// Control whether the I/O workload for the backup initial checkpoint will
    /// be limited, according to the `checkpoint_completion_target` setting on
    /// the PostgreSQL server. If set to true, an immediate checkpoint will be
    /// used, meaning PostgreSQL will complete the checkpoint as soon as
    /// possible. `false` by default.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "immediateCheckpoint"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub immediate_checkpoint: Option<bool>,
    /// If false, the function will return immediately after the backup is completed,
    /// without waiting for WAL to be archived.
    /// This behavior is only useful with backup software that independently monitors WAL archiving.
    /// Otherwise, WAL required to make the backup consistent might be missing and make the backup useless.
    /// By default, or when this parameter is true, pg_backup_stop will wait for WAL to be archived when archiving is
    /// enabled.
    /// On a standby, this means that it will wait only when archive_mode = always.
    /// If write activity on the primary is low, it may be useful to run pg_switch_wal on the primary in order to trigger
    /// an immediate segment switch.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "waitForArchive"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub wait_for_archive: Option<bool>,
}

/// Configuration parameters passed to the plugin managing this backup
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ScheduledBackupPluginConfiguration {
    /// Name is the name of the plugin managing this backup
    pub name: String,
    /// Parameters are the configuration parameters passed to the backup
    /// plugin for this backup
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub parameters: Option<BTreeMap<String, String>>,
}

/// Specification of the desired behavior of the ScheduledBackup.
/// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum ScheduledBackupTarget {
    #[serde(rename = "primary")]
    Primary,
    #[serde(rename = "prefer-standby")]
    PreferStandby,
}

/// Most recently observed status of the ScheduledBackup. This data may not be up
/// to date. Populated by the system. Read-only.
/// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct ScheduledBackupStatus {
    /// The latest time the schedule
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "lastCheckTime"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub last_check_time: Option<String>,
    /// Information when was the last time that backup was successfully scheduled.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "lastScheduleTime"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub last_schedule_time: Option<String>,
    /// Next time we will run a backup
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "nextScheduleTime"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub next_schedule_time: Option<String>,
}
