use crate::error::{BillingError, Result};
use crate::service::CloudAccountConfig;
use super::traits::RawBillItem;
pub async fn query_provider_items(
provider_name: &str,
config: &CloudAccountConfig,
billing_cycle: &str,
) -> Result<(Vec<RawBillItem>, &'static str)> {
match provider_name {
#[cfg(feature = "aliyun")]
"aliyun" => {
use super::aliyun::AliyunBillingAdapter;
use super::traits::BillingProvider;
let adapter = AliyunBillingAdapter::from_config(config)?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "aws")]
"aws" => {
use super::aws::AwsBillingAdapter;
use super::traits::BillingProvider;
let adapter = AwsBillingAdapter::from_config(config).await?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "tencentcloud")]
"tencentcloud" => {
use super::tencentcloud::TencentCloudBillingAdapter;
use super::traits::BillingProvider;
let adapter = TencentCloudBillingAdapter::from_config(config)?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "volcengine")]
"volcengine" => {
use super::traits::BillingProvider;
use super::volcengine::VolcengineBillingAdapter;
let adapter = VolcengineBillingAdapter::from_config(config)?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "ucloud")]
"ucloud" => {
use super::traits::BillingProvider;
use super::ucloud::UCloudBillingAdapter;
let adapter = UCloudBillingAdapter::from_config(config)?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "gcp")]
"gcp" => {
use super::gcp::GcpBillingAdapter;
use super::traits::BillingProvider;
let adapter = GcpBillingAdapter::from_config(config).await?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
#[cfg(feature = "cloudflare")]
"cloudflare" => {
use super::cloudflare::CloudflareBillingAdapter;
use super::traits::BillingProvider;
let adapter = CloudflareBillingAdapter::from_config(config)?;
let items = adapter.query_bill_items(billing_cycle).await?;
Ok((items, adapter.currency()))
}
_ => Err(BillingError::ServiceError(format!(
"Unknown or disabled provider: {}",
provider_name
))),
}
}