use std::collections::BTreeMap;
use jiff::Timestamp;
use serde::Deserialize;
use serde_json::Value;
use crate::backend::Command;
use crate::chart::Dependency;
use crate::go_json::omit_zero;
use crate::manifest::Manifest;
use crate::release::{ApplyMethod, Hook, Release, Revision, Status as ReleaseState};
macro_rules! read_command {
($(#[$meta:meta])* $name:ident => $output:ty) => {
$(#[$meta])*
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into))]
pub struct $name {
/// The `RELEASE_NAME` argument.
#[builder(start_fn)]
pub release: String,
pub revision: Option<Revision>,
}
impl $name {
#[must_use]
pub fn new(release: impl Into<String>) -> Self {
Self::builder(release).build()
}
}
impl Command for $name {
type Output = $output;
}
};
}
read_command! {
Status => Release
}
read_command! {
GetManifest => Manifest
}
read_command! {
GetHooks => Vec<Hook>
}
read_command! {
GetNotes => String
}
read_command! {
GetMetadata => ReleaseMetadata
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into))]
pub struct GetAll {
#[builder(start_fn)]
pub release: String,
pub revision: Option<Revision>,
pub template: Option<String>,
}
impl GetAll {
#[must_use]
pub fn new(release: impl Into<String>) -> Self {
Self::builder(release).build()
}
}
impl Command for GetAll {
type Output = String;
}
#[derive(Debug, Clone, PartialEq, Eq, bon::Builder)]
#[builder(on(String, into), on(bool, default))]
pub struct GetValues {
#[builder(start_fn)]
pub release: String,
pub all: bool,
pub revision: Option<Revision>,
}
impl GetValues {
#[must_use]
pub fn new(release: impl Into<String>) -> Self {
Self::builder(release).build()
}
}
impl Command for GetValues {
type Output = Value;
}
#[derive(Debug, Clone, PartialEq, Deserialize)]
pub struct ReleaseMetadata {
pub name: String,
pub chart: String,
pub version: String,
#[serde(rename = "appVersion", default)]
pub app_version: String,
#[serde(default)]
pub annotations: BTreeMap<String, String>,
#[serde(default)]
pub labels: BTreeMap<String, String>,
#[serde(default)]
pub dependencies: Vec<Dependency>,
pub namespace: String,
pub revision: Revision,
pub status: ReleaseState,
#[serde(rename = "deployedAt", default, with = "omit_zero")]
pub deployed_at: Option<Timestamp>,
#[serde(rename = "applyMethod", default)]
pub apply_method: Option<ApplyMethod>,
}