use crate::error::Result;
use crate::models::Subscription;
use crate::utils::AzCommandBuilder;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceGroupProperties {
#[serde(alias = "provisioningState")]
pub provisioning_state: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceGroup {
pub name: String,
pub location: String,
pub properties: ResourceGroupProperties,
pub tags: Option<std::collections::HashMap<String, String>>,
pub id: String,
#[serde(alias = "managedBy")]
pub managed_by: Option<String>,
}
pub struct AccountCommands;
impl AccountCommands {
pub async fn list_subscriptions() -> Result<Vec<Subscription>> {
AzCommandBuilder::new()
.subcommand("account")
.subcommand("list")
.execute()
.await
}
pub async fn show_subscription(subscription_id: Option<&str>) -> Result<Subscription> {
AzCommandBuilder::new()
.subcommand("account")
.subcommand("show")
.subscription(subscription_id)
.execute()
.await
}
pub async fn set_subscription(subscription_id: &str) -> Result<String> {
AzCommandBuilder::new()
.subcommand("account")
.subcommand("set")
.param("--subscription", subscription_id)
.execute_raw()
.await
}
pub async fn list_locations(subscription_id: Option<&str>) -> Result<Vec<serde_json::Value>> {
AzCommandBuilder::new()
.subcommand("account")
.subcommand("list-locations")
.subscription(subscription_id)
.execute()
.await
}
pub async fn list_resource_groups(subscription_id: Option<&str>) -> Result<Vec<ResourceGroup>> {
AzCommandBuilder::new()
.subcommand("group")
.subcommand("list")
.subscription(subscription_id)
.execute()
.await
}
pub async fn show_resource_group(name: &str, subscription_id: Option<&str>) -> Result<ResourceGroup> {
AzCommandBuilder::new()
.subcommand("group")
.subcommand("show")
.param("--name", name)
.subscription(subscription_id)
.execute()
.await
}
pub async fn create_resource_group(name: &str, location: &str, subscription_id: Option<&str>) -> Result<ResourceGroup> {
AzCommandBuilder::new()
.subcommand("group")
.subcommand("create")
.param("--name", name)
.param("--location", location)
.subscription(subscription_id)
.execute()
.await
}
pub async fn delete_resource_group(name: &str, subscription_id: Option<&str>) -> Result<String> {
AzCommandBuilder::new()
.subcommand("group")
.subcommand("delete")
.param("--name", name)
.flag("--yes")
.subscription(subscription_id)
.execute_raw()
.await
}
}