use std::time::Duration;
use serde::Serialize;
use crate::Month;
use crate::models::{DocumentStatus, ReviewStatus};
#[derive(Default)]
pub(crate) struct Query(pub(crate) Vec<(&'static str, String)>);
impl Query {
fn put(&mut self, key: &'static str, value: Option<impl ToString>) {
if let Some(v) = value {
let v = v.to_string();
if !v.is_empty() {
self.0.push((key, v));
}
}
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ExtractOptions {
pub idempotency_key: Option<String>,
}
impl ExtractOptions {
pub fn new() -> Self {
Self::default()
}
pub fn idempotency_key(mut self, key: impl Into<String>) -> Self {
self.idempotency_key = Some(key.into());
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WaitOptions {
pub timeout: Duration,
pub poll_interval: Duration,
}
impl Default for WaitOptions {
fn default() -> Self {
WaitOptions {
timeout: Duration::from_secs(120),
poll_interval: Duration::from_secs(2),
}
}
}
impl WaitOptions {
pub fn new() -> Self {
Self::default()
}
pub fn timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
pub fn poll_interval(mut self, interval: Duration) -> Self {
self.poll_interval = interval;
self
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ListDocumentsParams {
pub limit: Option<u32>,
pub offset: Option<u32>,
pub status: Option<DocumentStatus>,
pub flagged: bool,
pub q: Option<String>,
pub category: Option<String>,
}
impl ListDocumentsParams {
pub fn new() -> Self {
Self::default()
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn offset(mut self, offset: u32) -> Self {
self.offset = Some(offset);
self
}
pub fn status(mut self, status: DocumentStatus) -> Self {
self.status = Some(status);
self
}
pub fn flagged(mut self, flagged: bool) -> Self {
self.flagged = flagged;
self
}
pub fn q(mut self, q: impl Into<String>) -> Self {
self.q = Some(q.into());
self
}
pub fn category(mut self, category: impl Into<String>) -> Self {
self.category = Some(category.into());
self
}
pub(crate) fn query(&self) -> Query {
let mut q = Query::default();
q.put("limit", self.limit);
q.put("offset", self.offset);
q.put("status", self.status.as_ref());
q.put("flagged", self.flagged.then_some("true"));
q.put("q", self.q.as_ref());
q.put("category", self.category.as_ref());
q
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ListReviewQueueParams {
pub status: Option<ReviewStatus>,
}
impl ListReviewQueueParams {
pub fn new() -> Self {
Self::default()
}
pub fn status(mut self, status: ReviewStatus) -> Self {
self.status = Some(status);
self
}
pub(crate) fn query(&self) -> Query {
let mut q = Query::default();
q.put("status", self.status.as_ref());
q
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ReviewResolution {
#[default]
Resolved,
Dismissed,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
pub struct CreateWebhookEndpoint {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub events: Vec<String>,
}
impl CreateWebhookEndpoint {
pub fn new(url: impl Into<String>) -> Self {
CreateWebhookEndpoint {
url: url.into(),
..Self::default()
}
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn events<I, S>(mut self, events: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.events = events.into_iter().map(Into::into).collect();
self
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ListBillsParams {
pub paid: Option<bool>,
pub month: Option<Month>,
pub sender: Option<String>,
pub q: Option<String>,
pub limit: Option<u32>,
pub offset: Option<u32>,
}
impl ListBillsParams {
pub fn new() -> Self {
Self::default()
}
pub fn paid(mut self, paid: bool) -> Self {
self.paid = Some(paid);
self
}
pub fn month(mut self, month: Month) -> Self {
self.month = Some(month);
self
}
pub fn sender(mut self, sender: impl Into<String>) -> Self {
self.sender = Some(sender.into());
self
}
pub fn q(mut self, q: impl Into<String>) -> Self {
self.q = Some(q.into());
self
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn offset(mut self, offset: u32) -> Self {
self.offset = Some(offset);
self
}
pub(crate) fn query(&self) -> Query {
let mut q = Query::default();
q.put("paid", self.paid);
q.put("month", self.month);
q.put("sender", self.sender.as_ref());
q.put("q", self.q.as_ref());
q.put("limit", self.limit);
q.put("offset", self.offset);
q
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BillsSummaryParams {
pub today: Option<String>,
pub days: Option<u32>,
}
impl BillsSummaryParams {
pub fn new() -> Self {
Self::default()
}
pub fn today(mut self, today: impl Into<String>) -> Self {
self.today = Some(today.into());
self
}
pub fn days(mut self, days: u32) -> Self {
self.days = Some(days);
self
}
pub(crate) fn query(&self) -> Query {
let mut q = Query::default();
q.put("today", self.today.as_ref());
q.put("days", self.days);
q
}
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BillsStatsParams {
pub month: Option<Month>,
pub sender: Option<String>,
}
impl BillsStatsParams {
pub fn new() -> Self {
Self::default()
}
pub fn month(mut self, month: Month) -> Self {
self.month = Some(month);
self
}
pub fn sender(mut self, sender: impl Into<String>) -> Self {
self.sender = Some(sender.into());
self
}
pub(crate) fn query(&self) -> Query {
let mut q = Query::default();
q.put("month", self.month);
q.put("sender", self.sender.as_ref());
q
}
}