1use reqwest::Method;
2
3use crate::client::Client;
4use crate::error::Error;
5use crate::types::{CobvPayload, CobvResponse};
6
7impl Client {
8 pub async fn cobv_create(&self, payload: &CobvPayload) -> Result<CobvResponse, Error> {
9 self.send_authenticated(Method::POST, "/v2/cobv", Some(payload))
10 .await
11 }
12
13 pub async fn cobv_update(
14 &self,
15 txid: &str,
16 payload: &CobvPayload,
17 ) -> Result<CobvResponse, Error> {
18 let path = format!("/v2/cobv/{txid}");
19 self.send_authenticated(Method::PUT, &path, Some(payload))
20 .await
21 }
22
23 pub async fn cobv_patch(
24 &self,
25 txid: &str,
26 payload: &CobvPayload,
27 ) -> Result<CobvResponse, Error> {
28 let path = format!("/v2/cobv/{txid}");
29 self.send_authenticated(Method::PATCH, &path, Some(payload))
30 .await
31 }
32
33 pub async fn cobv_get(&self, txid: &str) -> Result<CobvResponse, Error> {
34 let path = format!("/v2/cobv/{txid}");
35 self.send_authenticated::<serde_json::Value, CobvResponse>(Method::GET, &path, None)
36 .await
37 }
38
39 pub async fn cobv_list(
40 &self,
41 cpf: Option<&str>,
42 status: Option<&str>,
43 limit: Option<i32>,
44 ) -> Result<Vec<CobvResponse>, Error> {
45 let mut path = String::from("/v2/cobv");
46 let mut params = Vec::new();
47
48 if let Some(c) = cpf {
49 params.push(format!("cpf={c}"));
50 }
51 if let Some(s) = status {
52 params.push(format!("status={s}"));
53 }
54 if let Some(l) = limit {
55 params.push(format!("limit={l}"));
56 }
57
58 if !params.is_empty() {
59 path.push('?');
60 path.push_str(¶ms.join("&"));
61 }
62
63 self.send_authenticated::<serde_json::Value, Vec<CobvResponse>>(Method::GET, &path, None)
64 .await
65 }
66}