1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use crate::model::voucherlist::{VoucherStatus, VoucherType};
use crate::model::Voucherlist;
use crate::request::impls::ById;
use crate::request::impls::Paginated;
use crate::request::Endpoint;
use crate::request::Request;
use crate::request::RequestWithState;
use std::marker::PhantomData;

// Not implementing the into trait here as this mustn't be public.
fn into<O: Clone, T: Clone, S: Clone>(
    request: RequestWithState<Voucherlist, O>,
) -> RequestWithState<Voucherlist, (T, S)> {
    RequestWithState {
        client: request.client,
        url: request.url,
        target: request.target,
        state: PhantomData,
    }
}

/// This type represents the state of a Request to the Voucherlist endpoint
/// that is ready to be sent
pub type VoucherlistStateFinished = (VoucherType, VoucherStatus);

/// This type represents the state of a Request to the Voucherlist endpoint
/// hasn't been started to be configured
pub type VoucherlistStateUnstarted = ();

/// This type represents the state of a Request to the Voucherlist endpoint
/// that configuration hasn't been finished
pub type VoucherlistState<T, S> = (T, S);

impl<S: Clone> Endpoint for RequestWithState<Voucherlist, S> {
    const ENDPOINT: &'static str = "voucherlist";
}

impl RequestWithState<Voucherlist, VoucherlistStateUnstarted> {
    /// Sets the voucher status for this request. Calling this function is mandatory
    pub fn type_(
        self,
        voucher_type: &VoucherType,
    ) -> RequestWithState<Voucherlist, VoucherlistState<VoucherType, ()>> {
        into::<_, (), ()>(self).type_(voucher_type)
    }
    /// Sets the voucher status for this request. Calling this function is mandatory
    pub fn status(
        self,
        voucher_status: &VoucherStatus,
    ) -> RequestWithState<Voucherlist, VoucherlistState<(), VoucherStatus>>
    {
        into::<_, (), ()>(self).status(voucher_status)
    }
}

impl<S: Clone> RequestWithState<Voucherlist, VoucherlistState<(), S>> {
    /// Sets the voucher status for this request. Calling this function is mandatory
    pub fn type_(
        mut self,
        voucher_type: &VoucherType,
    ) -> RequestWithState<Voucherlist, VoucherlistState<VoucherType, S>> {
        self.url.query_pairs_mut().append_pair(
            "voucherType",
            &serde_plain::to_string(voucher_type).unwrap(),
        );
        into(self)
    }
}

impl<T: Clone> RequestWithState<Voucherlist, VoucherlistState<T, ()>> {
    /// Sets the voucher status for this request. Calling this function is mandatory
    pub fn status(
        mut self,
        voucher_status: &VoucherStatus,
    ) -> RequestWithState<Voucherlist, VoucherlistState<T, VoucherStatus>> {
        self.url.query_pairs_mut().append_pair(
            "voucherStatus",
            &serde_plain::to_string(voucher_status).unwrap(),
        );
        into(self)
    }
}

/// # Examples
///
/// ```
/// use lexoffice::{ApiKey, Client};
/// use lexoffice::model::Voucherlist;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new(ApiKey::try_default().await?);
/// let uuid = uuid::Uuid::parse_str("f4add52b-44e3-474a-b718-890885094d9a")?;
/// let invoices = client.request::<Voucherlist>().by_id(uuid).await?;
/// println!("{:#?}", invoices);
/// # Ok(())
/// # }
/// ```
///
impl ById for Request<Voucherlist> {}

/// # Examples
///
/// ```
/// use lexoffice::{ApiKey, Client};
/// use lexoffice::model::Voucherlist;
/// use lexoffice::model::voucherlist::{VoucherStatus, VoucherType};
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let client = Client::new(ApiKey::try_default().await?);
/// let voucherlist = client
///        .request::<Voucherlist>()
///        .type_(&VoucherType::Invoice)
///        .status(&VoucherStatus::Open)
///        .page(0).await?;
/// println!("{:#?}", voucherlist);
/// # Ok(())
/// # }
/// ```
///
impl Paginated for RequestWithState<Voucherlist, VoucherlistStateFinished> {}