// WARNING: generated by kopium - manual changes will be overwritten
// kopium command: kopium -f subscriptions.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::*;

/// SubscriptionSpec defines the desired state of Subscription
#[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 = "Subscription",
    plural = "subscriptions"
)]
#[kube(namespaced)]
#[kube(status = "SubscriptionStatus")]
#[kube(derive = "Default")]
#[kube(derive = "PartialEq")]
pub struct SubscriptionSpec {
    /// The name of the PostgreSQL cluster that identifies the "subscriber"
    pub cluster: SubscriptionCluster,
    /// The name of the database where the publication will be installed in
    /// the "subscriber" cluster
    pub dbname: String,
    /// The name of the external cluster with the publication ("publisher")
    #[serde(rename = "externalClusterName")]
    pub external_cluster_name: String,
    /// The name of the subscription inside PostgreSQL
    pub name: String,
    /// Subscription parameters included in the `WITH` clause of the PostgreSQL
    /// `CREATE SUBSCRIPTION` command. Most parameters cannot be changed
    /// after the subscription is created and will be ignored if modified
    /// later, except for a limited set documented at:
    /// https://www.postgresql.org/docs/current/sql-altersubscription.html#SQL-ALTERSUBSCRIPTION-PARAMS-SET
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub parameters: Option<BTreeMap<String, String>>,
    /// The name of the database containing the publication on the external
    /// cluster. Defaults to the one in the external cluster definition.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "publicationDBName"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub publication_db_name: Option<String>,
    /// The name of the publication inside the PostgreSQL database in the
    /// "publisher"
    #[serde(rename = "publicationName")]
    pub publication_name: String,
    /// The policy for end-of-life maintenance of this subscription
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "subscriptionReclaimPolicy"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub subscription_reclaim_policy: Option<SubscriptionSubscriptionReclaimPolicy>,
}

/// The name of the PostgreSQL cluster that identifies the "subscriber"
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct SubscriptionCluster {
    /// Name of the referent.
    /// This field is effectively required, but due to backwards compatibility is
    /// allowed to be empty. Instances of this type with an empty value here are
    /// almost certainly wrong.
    /// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub name: Option<String>,
}

/// SubscriptionSpec defines the desired state of Subscription
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub enum SubscriptionSubscriptionReclaimPolicy {
    #[serde(rename = "delete")]
    Delete,
    #[serde(rename = "retain")]
    Retain,
}

/// SubscriptionStatus defines the observed state of Subscription
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "builder", derive(TypedBuilder))]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
pub struct SubscriptionStatus {
    /// Applied is true if the subscription was reconciled correctly
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub applied: Option<bool>,
    /// Message is the reconciliation output message
    #[serde(default, skip_serializing_if = "Option::is_none")]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub message: Option<String>,
    /// A sequence number representing the latest
    /// desired state that was synchronized
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "observedGeneration"
    )]
    #[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
    pub observed_generation: Option<i64>,
}
