use reqwest::Method;
use crate::client::Client;
use crate::error::EfiError;
use crate::types::{CobvPayload, CobvResponse};
impl Client {
pub fn cobv_create(&self, payload: &CobvPayload) -> Result<CobvResponse, EfiError> {
self.send_authenticated(Method::POST, "/v2/cobv", Some(payload))
}
pub fn cobv_update(&self, txid: &str, payload: &CobvPayload) -> Result<CobvResponse, EfiError> {
let path = format!("/v2/cobv/{txid}");
self.send_authenticated(Method::PUT, &path, Some(payload))
}
pub fn cobv_patch(&self, txid: &str, payload: &CobvPayload) -> Result<CobvResponse, EfiError> {
let path = format!("/v2/cobv/{txid}");
self.send_authenticated(Method::PATCH, &path, Some(payload))
}
pub fn cobv_get(&self, txid: &str) -> Result<CobvResponse, EfiError> {
let path = format!("/v2/cobv/{txid}");
self.send_authenticated::<serde_json::Value, CobvResponse>(Method::GET, &path, None)
}
pub fn cobv_list(
&self,
cpf: Option<&str>,
status: Option<&str>,
limit: Option<i32>,
) -> Result<Vec<CobvResponse>, EfiError> {
let mut path = String::from("/v2/cobv");
let mut params = Vec::new();
if let Some(c) = cpf {
params.push(format!("cpf={c}"));
}
if let Some(s) = status {
params.push(format!("status={s}"));
}
if let Some(l) = limit {
params.push(format!("limit={l}"));
}
if !params.is_empty() {
path.push('?');
path.push_str(¶ms.join("&"));
}
self.send_authenticated::<serde_json::Value, Vec<CobvResponse>>(Method::GET, &path, None)
}
}