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
use serde::Serialize;

use crate::{
    auth::{AuthFlow, Verifier},
    error::Result,
    model::search::SearchResults,
};

use super::{Builder, Endpoint, Limit};

impl Endpoint for SearchEndpoint {}

#[derive(Clone, Debug, Default, Serialize)]
pub struct SearchEndpoint {
    #[serde(rename = "q")]
    pub(crate) query: String,
    pub(crate) r#type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub(crate) market: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub(crate) limit: Option<Limit>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub(crate) offset: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub(crate) include_external: Option<bool>,
}

impl<F: AuthFlow, V: Verifier> Builder<'_, F, V, SearchEndpoint> {
    #[doc = include_str!("../docs/market.md")]
    pub fn market(mut self, market: impl Into<String>) -> Self {
        self.endpoint.market = Some(market.into());
        self
    }

    #[doc = include_str!("../docs/limit.md")]
    pub fn limit(mut self, limit: u32) -> Self {
        self.endpoint.limit = Some(Limit::new(limit));
        self
    }

    #[doc = include_str!("../docs/offset.md")]
    pub fn offset(mut self, offset: u32) -> Self {
        self.endpoint.offset = Some(offset);
        self
    }

    /// If specified, it signals that the client can play externally hosted audio content,
    /// and marks the content as playable in the response.
    ///
    /// By default externally hosted audio content is marked as unplayable in the response.
    pub fn include_external(mut self, include_external: bool) -> Self {
        self.endpoint.include_external = Some(include_external);
        self
    }

    #[doc = include_str!("../docs/send.md")]
    pub async fn get(self) -> Result<SearchResults> {
        self.spotify.get("/search".to_owned(), self.endpoint).await
    }
}