// authentik
//
// Making authentication simple.
//
// The version of the OpenAPI document: 2026.5.0-rc1
// Contact: hello@goauthentik.io
// Generated by: https://openapi-generator.tech

use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};

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

/// struct for typed errors of method [`core_brands_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CoreBrandsListError {
    Status400(models::ValidationError),
    Status403(models::GenericError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`core_groups_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CoreGroupsListError {
    Status400(models::ValidationError),
    Status403(models::GenericError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`core_users_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CoreUsersListError {
    Status400(models::ValidationError),
    Status403(models::GenericError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`core_users_me_retrieve`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CoreUsersMeRetrieveError {
    Status400(models::ValidationError),
    Status403(models::GenericError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`core_users_retrieve`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CoreUsersRetrieveError {
    Status400(models::ValidationError),
    Status403(models::GenericError),
    UnknownValue(serde_json::Value),
}

/// Brand Viewset
pub async fn core_brands_list(
    configuration: &configuration::Configuration,
    brand_uuid: Option<&str>,
    branding_default_flow_background: Option<&str>,
    branding_favicon: Option<&str>,
    branding_logo: Option<&str>,
    branding_title: Option<&str>,
    client_certificates: Option<Vec<uuid::Uuid>>,
    default: Option<bool>,
    domain: Option<&str>,
    flow_authentication: Option<&str>,
    flow_device_code: Option<&str>,
    flow_invalidation: Option<&str>,
    flow_recovery: Option<&str>,
    flow_unenrollment: Option<&str>,
    flow_user_settings: Option<&str>,
    ordering: Option<&str>,
    page: Option<i32>,
    page_size: Option<i32>,
    search: Option<&str>,
    web_certificate: Option<&str>,
) -> Result<models::PaginatedBrandList, Error<CoreBrandsListError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_brand_uuid = brand_uuid;
    let p_query_branding_default_flow_background = branding_default_flow_background;
    let p_query_branding_favicon = branding_favicon;
    let p_query_branding_logo = branding_logo;
    let p_query_branding_title = branding_title;
    let p_query_client_certificates = client_certificates;
    let p_query_default = default;
    let p_query_domain = domain;
    let p_query_flow_authentication = flow_authentication;
    let p_query_flow_device_code = flow_device_code;
    let p_query_flow_invalidation = flow_invalidation;
    let p_query_flow_recovery = flow_recovery;
    let p_query_flow_unenrollment = flow_unenrollment;
    let p_query_flow_user_settings = flow_user_settings;
    let p_query_ordering = ordering;
    let p_query_page = page;
    let p_query_page_size = page_size;
    let p_query_search = search;
    let p_query_web_certificate = web_certificate;

    let uri_str = format!("{}/core/brands/", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_brand_uuid {
        req_builder = req_builder.query(&[("brand_uuid", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_branding_default_flow_background {
        req_builder =
            req_builder.query(&[("branding_default_flow_background", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_branding_favicon {
        req_builder = req_builder.query(&[("branding_favicon", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_branding_logo {
        req_builder = req_builder.query(&[("branding_logo", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_branding_title {
        req_builder = req_builder.query(&[("branding_title", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_client_certificates {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("client_certificates".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "client_certificates",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_default {
        req_builder = req_builder.query(&[("default", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_domain {
        req_builder = req_builder.query(&[("domain", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_authentication {
        req_builder = req_builder.query(&[("flow_authentication", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_device_code {
        req_builder = req_builder.query(&[("flow_device_code", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_invalidation {
        req_builder = req_builder.query(&[("flow_invalidation", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_recovery {
        req_builder = req_builder.query(&[("flow_recovery", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_unenrollment {
        req_builder = req_builder.query(&[("flow_unenrollment", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_flow_user_settings {
        req_builder = req_builder.query(&[("flow_user_settings", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_ordering {
        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page {
        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_search {
        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_web_certificate {
        req_builder = req_builder.query(&[("web_certificate", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to \
                     `models::PaginatedBrandList`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to \
                     `models::PaginatedBrandList`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CoreBrandsListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Group Viewset
pub async fn core_groups_list(
    configuration: &configuration::Configuration,
    attributes: Option<&str>,
    include_children: Option<bool>,
    include_inherited_roles: Option<bool>,
    include_parents: Option<bool>,
    include_users: Option<bool>,
    is_superuser: Option<bool>,
    members_by_pk: Option<Vec<i32>>,
    members_by_username: Option<Vec<String>>,
    name: Option<&str>,
    ordering: Option<&str>,
    page: Option<i32>,
    page_size: Option<i32>,
    search: Option<&str>,
) -> Result<models::PaginatedGroupList, Error<CoreGroupsListError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_attributes = attributes;
    let p_query_include_children = include_children;
    let p_query_include_inherited_roles = include_inherited_roles;
    let p_query_include_parents = include_parents;
    let p_query_include_users = include_users;
    let p_query_is_superuser = is_superuser;
    let p_query_members_by_pk = members_by_pk;
    let p_query_members_by_username = members_by_username;
    let p_query_name = name;
    let p_query_ordering = ordering;
    let p_query_page = page;
    let p_query_page_size = page_size;
    let p_query_search = search;

    let uri_str = format!("{}/core/groups/", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_attributes {
        req_builder = req_builder.query(&[("attributes", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_include_children {
        req_builder = req_builder.query(&[("include_children", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_include_inherited_roles {
        req_builder = req_builder.query(&[("include_inherited_roles", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_include_parents {
        req_builder = req_builder.query(&[("include_parents", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_include_users {
        req_builder = req_builder.query(&[("include_users", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_is_superuser {
        req_builder = req_builder.query(&[("is_superuser", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_members_by_pk {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("members_by_pk".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "members_by_pk",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_members_by_username {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("members_by_username".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "members_by_username",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_name {
        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_ordering {
        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page {
        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_search {
        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to \
                     `models::PaginatedGroupList`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to \
                     `models::PaginatedGroupList`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CoreGroupsListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// User Viewset
pub async fn core_users_list(
    configuration: &configuration::Configuration,
    attributes: Option<&str>,
    date_joined: Option<String>,
    date_joined__gt: Option<String>,
    date_joined__lt: Option<String>,
    email: Option<&str>,
    groups_by_name: Option<Vec<String>>,
    groups_by_pk: Option<Vec<uuid::Uuid>>,
    include_groups: Option<bool>,
    include_roles: Option<bool>,
    is_active: Option<bool>,
    is_superuser: Option<bool>,
    last_login: Option<String>,
    last_login__gt: Option<String>,
    last_login__isnull: Option<bool>,
    last_login__lt: Option<String>,
    last_updated: Option<String>,
    last_updated__gt: Option<String>,
    last_updated__lt: Option<String>,
    name: Option<&str>,
    ordering: Option<&str>,
    page: Option<i32>,
    page_size: Option<i32>,
    path: Option<&str>,
    path_startswith: Option<&str>,
    roles_by_name: Option<Vec<String>>,
    roles_by_pk: Option<Vec<uuid::Uuid>>,
    search: Option<&str>,
    r#type: Option<Vec<models::UserTypeEnum>>,
    username: Option<&str>,
    uuid: Option<&str>,
) -> Result<models::PaginatedUserList, Error<CoreUsersListError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_attributes = attributes;
    let p_query_date_joined = date_joined;
    let p_query_date_joined__gt = date_joined__gt;
    let p_query_date_joined__lt = date_joined__lt;
    let p_query_email = email;
    let p_query_groups_by_name = groups_by_name;
    let p_query_groups_by_pk = groups_by_pk;
    let p_query_include_groups = include_groups;
    let p_query_include_roles = include_roles;
    let p_query_is_active = is_active;
    let p_query_is_superuser = is_superuser;
    let p_query_last_login = last_login;
    let p_query_last_login__gt = last_login__gt;
    let p_query_last_login__isnull = last_login__isnull;
    let p_query_last_login__lt = last_login__lt;
    let p_query_last_updated = last_updated;
    let p_query_last_updated__gt = last_updated__gt;
    let p_query_last_updated__lt = last_updated__lt;
    let p_query_name = name;
    let p_query_ordering = ordering;
    let p_query_page = page;
    let p_query_page_size = page_size;
    let p_query_path = path;
    let p_query_path_startswith = path_startswith;
    let p_query_roles_by_name = roles_by_name;
    let p_query_roles_by_pk = roles_by_pk;
    let p_query_search = search;
    let p_query_type = r#type;
    let p_query_username = username;
    let p_query_uuid = uuid;

    let uri_str = format!("{}/core/users/", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_attributes {
        req_builder = req_builder.query(&[("attributes", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_date_joined {
        req_builder = req_builder.query(&[("date_joined", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_date_joined__gt {
        req_builder = req_builder.query(&[("date_joined__gt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_date_joined__lt {
        req_builder = req_builder.query(&[("date_joined__lt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_email {
        req_builder = req_builder.query(&[("email", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_groups_by_name {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("groups_by_name".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "groups_by_name",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_groups_by_pk {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("groups_by_pk".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "groups_by_pk",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_include_groups {
        req_builder = req_builder.query(&[("include_groups", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_include_roles {
        req_builder = req_builder.query(&[("include_roles", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_is_active {
        req_builder = req_builder.query(&[("is_active", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_is_superuser {
        req_builder = req_builder.query(&[("is_superuser", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_login {
        req_builder = req_builder.query(&[("last_login", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_login__gt {
        req_builder = req_builder.query(&[("last_login__gt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_login__isnull {
        req_builder = req_builder.query(&[("last_login__isnull", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_login__lt {
        req_builder = req_builder.query(&[("last_login__lt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_updated {
        req_builder = req_builder.query(&[("last_updated", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_updated__gt {
        req_builder = req_builder.query(&[("last_updated__gt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_last_updated__lt {
        req_builder = req_builder.query(&[("last_updated__lt", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_name {
        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_ordering {
        req_builder = req_builder.query(&[("ordering", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page {
        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_path {
        req_builder = req_builder.query(&[("path", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_path_startswith {
        req_builder = req_builder.query(&[("path_startswith", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_roles_by_name {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("roles_by_name".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "roles_by_name",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_roles_by_pk {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("roles_by_pk".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "roles_by_pk",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_search {
        req_builder = req_builder.query(&[("search", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_type {
        req_builder = match "multi" {
            "multi" => req_builder.query(
                &param_value
                    .into_iter()
                    .map(|p| ("type".to_owned(), p.to_string()))
                    .collect::<Vec<(std::string::String, std::string::String)>>(),
            ),
            _ => req_builder.query(&[(
                "type",
                &param_value
                    .into_iter()
                    .map(|p| p.to_string())
                    .collect::<Vec<String>>()
                    .join(",")
                    .to_string(),
            )]),
        };
    }
    if let Some(ref param_value) = p_query_username {
        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_uuid {
        req_builder = req_builder.query(&[("uuid", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to \
                     `models::PaginatedUserList`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to \
                     `models::PaginatedUserList`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CoreUsersListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Get information about current user
pub async fn core_users_me_retrieve(
    configuration: &configuration::Configuration,
) -> Result<models::SessionUser, Error<CoreUsersMeRetrieveError>> {
    let uri_str = format!("{}/core/users/me/", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to \
                     `models::SessionUser`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to \
                     `models::SessionUser`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CoreUsersMeRetrieveError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// User Viewset
pub async fn core_users_retrieve(
    configuration: &configuration::Configuration,
    id: i32,
) -> Result<models::User, Error<CoreUsersRetrieveError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_id = id;

    let uri_str = format!(
        "{}/core/users/{id}/",
        configuration.base_path,
        id = p_path_id
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to \
                     `models::User`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to \
                     `models::User`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<CoreUsersRetrieveError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}
