/*
 * Client Portal Web API
 *
 * Client Portal Web API
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;

use crate::apis::ResponseContent;
use super::{Error, configuration};


/// struct for typed errors of method `fyi_deliveryoptions_device_id_delete`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDeliveryoptionsDeviceIdDeleteError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_deliveryoptions_device_post`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDeliveryoptionsDevicePostError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_deliveryoptions_email_put`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDeliveryoptionsEmailPutError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_deliveryoptions_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDeliveryoptionsGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_disclaimer_typecode_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDisclaimerTypecodeGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_disclaimer_typecode_put`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiDisclaimerTypecodePutError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_notifications_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiNotificationsGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_notifications_more_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiNotificationsMoreGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_notifications_notification_id_put`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiNotificationsNotificationIdPutError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_settings_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiSettingsGetError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_settings_typecode_post`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiSettingsTypecodePostError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method `fyi_unreadnumber_get`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FyiUnreadnumberGetError {
    UnknownValue(serde_json::Value),
}


pub async fn fyi_deliveryoptions_device_id_delete(configuration: &configuration::Configuration, device_id: &str) -> Result<serde_json::Value, Error<FyiDeliveryoptionsDeviceIdDeleteError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/deliveryoptions/{deviceId}", configuration.base_path, deviceId=crate::apis::urlencode(device_id));
    let mut local_var_req_builder = local_var_client.delete(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDeliveryoptionsDeviceIdDeleteError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_deliveryoptions_device_post(configuration: &configuration::Configuration, body: crate::models::InlineObject1) -> Result<crate::models::InlineResponse2004, Error<FyiDeliveryoptionsDevicePostError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/deliveryoptions/device", configuration.base_path);
    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    local_var_req_builder = local_var_req_builder.json(&body);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDeliveryoptionsDevicePostError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_deliveryoptions_email_put(configuration: &configuration::Configuration, enabled: &str) -> Result<crate::models::InlineResponse2004, Error<FyiDeliveryoptionsEmailPutError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/deliveryoptions/email", configuration.base_path);
    let mut local_var_req_builder = local_var_client.put(local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("enabled", &enabled.to_string())]);
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDeliveryoptionsEmailPutError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// options for sending fyis to email and other devices 
pub async fn fyi_deliveryoptions_get(configuration: &configuration::Configuration, ) -> Result<crate::models::InlineResponse2005, Error<FyiDeliveryoptionsGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/deliveryoptions", configuration.base_path);
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDeliveryoptionsGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_disclaimer_typecode_get(configuration: &configuration::Configuration, typecode: &str) -> Result<crate::models::InlineResponse2003, Error<FyiDisclaimerTypecodeGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/disclaimer/{typecode}", configuration.base_path, typecode=crate::apis::urlencode(typecode));
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDisclaimerTypecodeGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_disclaimer_typecode_put(configuration: &configuration::Configuration, typecode: &str) -> Result<crate::models::InlineResponse2004, Error<FyiDisclaimerTypecodePutError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/disclaimer/{typecode}", configuration.base_path, typecode=crate::apis::urlencode(typecode));
    let mut local_var_req_builder = local_var_client.put(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiDisclaimerTypecodePutError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_notifications_get(configuration: &configuration::Configuration, max: &str, exclude: Option<&str>, include: Option<&str>) -> Result<Vec<serde_json::Value>, Error<FyiNotificationsGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/notifications", configuration.base_path);
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    if let Some(ref local_var_str) = exclude {
        local_var_req_builder = local_var_req_builder.query(&[("exclude", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = include {
        local_var_req_builder = local_var_req_builder.query(&[("include", &local_var_str.to_string())]);
    }
    local_var_req_builder = local_var_req_builder.query(&[("max", &max.to_string())]);
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiNotificationsGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_notifications_more_get(configuration: &configuration::Configuration, id: &str) -> Result<Vec<serde_json::Value>, Error<FyiNotificationsMoreGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/notifications/more", configuration.base_path);
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiNotificationsMoreGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

pub async fn fyi_notifications_notification_id_put(configuration: &configuration::Configuration, notification_id: &str) -> Result<serde_json::Value, Error<FyiNotificationsNotificationIdPutError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/notifications/{notificationId}", configuration.base_path, notificationId=crate::apis::urlencode(notification_id));
    let mut local_var_req_builder = local_var_client.put(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiNotificationsNotificationIdPutError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Return the current choices of subscriptions, we can toggle the option 
pub async fn fyi_settings_get(configuration: &configuration::Configuration, ) -> Result<Vec<crate::models::InlineResponse2002>, Error<FyiSettingsGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/settings", configuration.base_path);
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiSettingsGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Configure which typecode you would like to enable/disable. 
pub async fn fyi_settings_typecode_post(configuration: &configuration::Configuration, typecode: &str, body: crate::models::InlineObject) -> Result<serde_json::Value, Error<FyiSettingsTypecodePostError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/settings/{typecode}", configuration.base_path, typecode=crate::apis::urlencode(typecode));
    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    local_var_req_builder = local_var_req_builder.json(&body);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiSettingsTypecodePostError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

/// Returns the total number of unread fyis 
pub async fn fyi_unreadnumber_get(configuration: &configuration::Configuration, ) -> Result<crate::models::InlineResponse2001, Error<FyiUnreadnumberGetError>> {

    let local_var_client = &configuration.client;

    let local_var_uri_str = format!("{}/fyi/unreadnumber", configuration.base_path);
    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<FyiUnreadnumberGetError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}

