use crate::api::ApiClient;
use crate::types::app::AppVersion;

pub struct AppVersionSdk {
    app_version: AppVersion,
    api_client: ApiClient,
}

impl AppVersionSdk {
    pub fn new(app_version: AppVersion, api_client: ApiClient) -> Self {
        Self {
            app_version,
            api_client,
        }
    }

    pub fn set_as_published(&mut self, published: Option<bool>) -> crate::Result<()> {
        let published = published.unwrap_or(true);
        let data = serde_json::json!({"set_as_published": published});
        self.api_client.patch_json(
            &format!("/app_versions/{}/", self.app_version.public_id),
            &data,
        )?;
        Ok(())
    }

    pub fn set_as_default(&mut self) -> crate::Result<()> {
        let data = serde_json::json!({"set_as_active": true});
        self.api_client.patch_json(
            &format!("/app_versions/{}/", self.app_version.public_id),
            &data,
        )?;
        Ok(())
    }
}
