// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!

use crate::b2b::idp::ScopeResult;
use crate::b2b::organizations::Member;
use crate::b2b::organizations::Organization;
use crate::consumer::connected_apps::ConnectedAppPublic;
use serde::{Deserialize, Serialize};

/// AuthorizeRequest: Request type for `OAuth.authorize`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AuthorizeRequest {
    /// consent_granted: Indicates whether the user granted the requested scopes.
    pub consent_granted: bool,
    /// scopes: An array of scopes requested by the client.
    pub scopes: std::vec::Vec<String>,
    /// client_id: The ID of the Connected App client.
    pub client_id: String,
    /// redirect_uri: The callback URI used to redirect the user after authentication. This is the same URI
    /// provided at the start of the OAuth flow.  This field is required when using the `authorization_code`
    /// grant.
    pub redirect_uri: String,
    /// response_type: The OAuth 2.0 response type. For authorization code flows this value is `code`.
    pub response_type: String,
    /// organization_id: Globally unique UUID that identifies a specific Organization. The `organization_id` is
    /// critical to perform operations on an Organization, so be sure to preserve this value. You may also use
    /// the organization_slug or organization_external_id here as a convenience.
    pub organization_id: std::option::Option<String>,
    /// member_id: Globally unique UUID that identifies a specific Member. The `member_id` is critical to
    /// perform operations on a Member, so be sure to preserve this value. You may use an external_id here if
    /// one is set for the member.
    pub member_id: std::option::Option<String>,
    /// session_token: A secret token for a given Stytch Session.
    pub session_token: std::option::Option<String>,
    /// session_jwt: The JSON Web Token (JWT) for a given Stytch Session.
    pub session_jwt: std::option::Option<String>,
    /// prompt: Space separated list that specifies how the Authorization Server should prompt the user for
    /// reauthentication and consent. Only `consent` is supported today.
    pub prompt: std::option::Option<String>,
    /// state: An opaque value used to maintain state between the request and callback.
    pub state: std::option::Option<String>,
    /// nonce: A string used to associate a client session with an ID token to mitigate replay attacks.
    pub nonce: std::option::Option<String>,
    /// code_challenge: A base64url encoded challenge derived from the code verifier for PKCE flows.
    pub code_challenge: std::option::Option<String>,
}
/// AuthorizeResponse: Response type for `OAuth.authorize`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AuthorizeResponse {
    /// request_id: Globally unique UUID that is returned with every API call. This value is important to log
    /// for debugging purposes; we may ask for this value to help identify a specific API call when helping you
    /// debug an issue.
    pub request_id: String,
    /// redirect_uri: The callback URI used to redirect the user after authentication. This is the same URI
    /// provided at the start of the OAuth flow.  This field is required when using the `authorization_code`
    /// grant.
    pub redirect_uri: String,
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
    /// authorization_code: A one-time use code that can be exchanged for tokens.
    pub authorization_code: std::option::Option<String>,
}
/// AuthorizeStartRequest: Request type for `OAuth.authorize_start`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AuthorizeStartRequest {
    /// client_id: The ID of the Connected App client.
    pub client_id: String,
    /// redirect_uri: The callback URI used to redirect the user after authentication. This is the same URI
    /// provided at the start of the OAuth flow.  This field is required when using the `authorization_code`
    /// grant.
    pub redirect_uri: String,
    /// response_type: The OAuth 2.0 response type. For authorization code flows this value is `code`.
    pub response_type: String,
    /// scopes: An array of scopes requested by the client.
    pub scopes: std::vec::Vec<String>,
    /// organization_id: Globally unique UUID that identifies a specific Organization. The `organization_id` is
    /// critical to perform operations on an Organization, so be sure to preserve this value. You may also use
    /// the organization_slug or organization_external_id here as a convenience.
    pub organization_id: std::option::Option<String>,
    /// member_id: Globally unique UUID that identifies a specific Member. The `member_id` is critical to
    /// perform operations on a Member, so be sure to preserve this value. You may use an external_id here if
    /// one is set for the member.
    pub member_id: std::option::Option<String>,
    /// session_token: A secret token for a given Stytch Session.
    pub session_token: std::option::Option<String>,
    /// session_jwt: The JSON Web Token (JWT) for a given Stytch Session.
    pub session_jwt: std::option::Option<String>,
    /// prompt: Space separated list that specifies how the Authorization Server should prompt the user for
    /// reauthentication and consent. Only `consent` is supported today.
    pub prompt: std::option::Option<String>,
}
/// AuthorizeStartResponse: Response type for `OAuth.authorize_start`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AuthorizeStartResponse {
    /// request_id: Globally unique UUID that is returned with every API call. This value is important to log
    /// for debugging purposes; we may ask for this value to help identify a specific API call when helping you
    /// debug an issue.
    pub request_id: String,
    /// member_id: Globally unique UUID that identifies a specific Member.
    pub member_id: String,
    /// member: The [Member object](https://stytch.com/docs/b2b/api/member-object)
    pub member: Member,
    /// organization: The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
    pub organization: Organization,
    pub client: ConnectedAppPublic,
    /// consent_required: Whether the user must provide explicit consent for the authorization request.
    pub consent_required: bool,
    /// scope_results: Details about each requested scope.
    pub scope_results: std::vec::Vec<ScopeResult>,
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
}

pub struct OAuth {
    http_client: crate::client::Client,
}

impl OAuth {
    pub fn new(http_client: crate::client::Client) -> Self {
        Self {
            http_client: http_client.clone(),
        }
    }

    pub async fn authorize_start(
        &self,
        body: AuthorizeStartRequest,
    ) -> crate::Result<AuthorizeStartResponse> {
        let path = String::from("/v1/b2b/idp/oauth/authorize/start");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
    pub async fn authorize(&self, body: AuthorizeRequest) -> crate::Result<AuthorizeResponse> {
        let path = String::from("/v1/b2b/idp/oauth/authorize");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
}
