use crate::models::PaginationParams;
use serde::{Deserialize, Serialize};
use crate::filters::{billable_metric::BillableMetricFilter, common::ListFilters};
use crate::models::{
BillableMetricAggregationType, BillableMetricFilter as BillableMetricFilterModel,
BillableMetricRoundingFunction, BillableMetricWeightedInterval,
};
#[derive(Debug, Clone)]
pub struct ListBillableMetricsRequest {
pub pagination: PaginationParams,
pub filters: BillableMetricFilter,
}
impl ListBillableMetricsRequest {
pub fn new() -> Self {
Self {
pagination: PaginationParams::default(),
filters: BillableMetricFilter::default(),
}
}
pub fn with_pagination(mut self, pagination: PaginationParams) -> Self {
self.pagination = pagination;
self
}
pub fn with_filters(mut self, filters: BillableMetricFilter) -> Self {
self.filters = filters;
self
}
pub fn to_query_params(&self) -> Vec<(&str, String)> {
let mut params = self.pagination.to_query_params();
params.extend(self.filters.to_query_params());
params
}
}
impl Default for ListBillableMetricsRequest {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct GetBillableMetricRequest {
pub code: String,
}
impl GetBillableMetricRequest {
pub fn new(code: String) -> Self {
Self { code }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateBillableMetricInput {
pub name: String,
pub code: String,
pub description: Option<String>,
pub aggregation_type: BillableMetricAggregationType,
pub recurring: Option<bool>,
pub rounding_function: Option<BillableMetricRoundingFunction>,
pub rounding_precision: Option<i32>,
pub expression: Option<String>,
pub field_name: Option<String>,
pub weighted_interval: Option<BillableMetricWeightedInterval>,
pub filters: Option<Vec<BillableMetricFilterModel>>,
}
impl CreateBillableMetricInput {
pub fn new(
name: String,
code: String,
aggregation_type: BillableMetricAggregationType,
) -> Self {
Self {
name,
code,
aggregation_type,
description: None,
recurring: None,
rounding_function: None,
rounding_precision: None,
expression: None,
field_name: None,
weighted_interval: None,
filters: None,
}
}
pub fn with_description(mut self, description: String) -> Self {
self.description = Some(description);
self
}
pub fn with_recurring(mut self, recurring: bool) -> Self {
self.recurring = Some(recurring);
self
}
pub fn with_rounding_function(
mut self,
rounding_function: BillableMetricRoundingFunction,
) -> Self {
self.rounding_function = Some(rounding_function);
self
}
pub fn with_rounding_precision(mut self, precision: i32) -> Self {
self.rounding_precision = Some(precision);
self
}
pub fn with_expression(mut self, expression: String) -> Self {
self.expression = Some(expression);
self
}
pub fn with_field_name(mut self, field_name: String) -> Self {
self.field_name = Some(field_name);
self
}
pub fn with_weighted_interval(mut self, interval: BillableMetricWeightedInterval) -> Self {
self.weighted_interval = Some(interval);
self
}
pub fn with_filters(mut self, filters: Vec<BillableMetricFilterModel>) -> Self {
self.filters = Some(filters);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateBillableMetricRequest {
pub billable_metric: CreateBillableMetricInput,
}
impl CreateBillableMetricRequest {
pub fn new(billable_metric: CreateBillableMetricInput) -> Self {
Self { billable_metric }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateBillableMetricInput {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub aggregation_type: Option<BillableMetricAggregationType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub recurring: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rounding_function: Option<BillableMetricRoundingFunction>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rounding_precision: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expression: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub field_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub weighted_interval: Option<BillableMetricWeightedInterval>,
#[serde(skip_serializing_if = "Option::is_none")]
pub filters: Option<Vec<BillableMetricFilterModel>>,
}
impl UpdateBillableMetricInput {
pub fn new() -> Self {
Self {
name: None,
code: None,
description: None,
aggregation_type: None,
recurring: None,
rounding_function: None,
rounding_precision: None,
expression: None,
field_name: None,
weighted_interval: None,
filters: None,
}
}
pub fn with_name(mut self, name: String) -> Self {
self.name = Some(name);
self
}
pub fn with_code(mut self, code: String) -> Self {
self.code = Some(code);
self
}
pub fn with_description(mut self, description: String) -> Self {
self.description = Some(description);
self
}
pub fn with_aggregation_type(
mut self,
aggregation_type: BillableMetricAggregationType,
) -> Self {
self.aggregation_type = Some(aggregation_type);
self
}
pub fn with_recurring(mut self, recurring: bool) -> Self {
self.recurring = Some(recurring);
self
}
pub fn with_rounding_function(
mut self,
rounding_function: BillableMetricRoundingFunction,
) -> Self {
self.rounding_function = Some(rounding_function);
self
}
pub fn with_rounding_precision(mut self, precision: i32) -> Self {
self.rounding_precision = Some(precision);
self
}
pub fn with_expression(mut self, expression: String) -> Self {
self.expression = Some(expression);
self
}
pub fn with_field_name(mut self, field_name: String) -> Self {
self.field_name = Some(field_name);
self
}
pub fn with_weighted_interval(mut self, interval: BillableMetricWeightedInterval) -> Self {
self.weighted_interval = Some(interval);
self
}
pub fn with_filters(mut self, filters: Vec<BillableMetricFilterModel>) -> Self {
self.filters = Some(filters);
self
}
}
impl Default for UpdateBillableMetricInput {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateBillableMetricRequest {
#[serde(skip)]
pub code: String,
pub billable_metric: UpdateBillableMetricInput,
}
impl UpdateBillableMetricRequest {
pub fn new(code: String, input: UpdateBillableMetricInput) -> Self {
Self {
code,
billable_metric: input,
}
}
}