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

use crate::consumer::passwords_email::Email;
use crate::consumer::passwords_existing_password::ExistingPassword;
use crate::consumer::passwords_session::Sessions;
use crate::consumer::sessions::Session;
use crate::consumer::users::Name;
use crate::consumer::users::User;
use serde::{Deserialize, Serialize};

/// Argon2Config:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Argon2Config {
    /// salt: The salt value.
    pub salt: String,
    /// iteration_amount: The iteration amount.
    pub iteration_amount: i32,
    /// memory: The memory in kibibytes.
    pub memory: i32,
    /// threads: The thread value, also known as the parallelism factor.
    pub threads: i32,
    /// key_length: The key length, also known as the hash length.
    pub key_length: i32,
}
/// Feedback:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Feedback {
    /// warning: For `zxcvbn` validation, contains an end user consumable warning if the password is valid but
    /// not strong enough.
    pub warning: String,
    /// suggestions: For `zxcvbn` validation, contains end user consumable suggestions on how to improve the
    /// strength of the password.
    pub suggestions: std::vec::Vec<String>,
    /// luds_requirements: Contains which LUDS properties are fulfilled by the password and which are missing to
    /// convert an invalid password into a valid one. You'll use these fields to provide feedback to the user on
    /// how to improve the password.
    pub luds_requirements: std::option::Option<LUDSRequirements>,
}
/// LUDSRequirements:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LUDSRequirements {
    /// has_lower_case: For LUDS validation, whether the password contains at least one lowercase letter.
    pub has_lower_case: bool,
    /// has_upper_case: For LUDS validation, whether the password contains at least one uppercase letter.
    pub has_upper_case: bool,
    /// has_digit: For LUDS validation, whether the password contains at least one digit.
    pub has_digit: bool,
    /// has_symbol: For LUDS validation, whether the password contains at least one symbol. Any UTF8 character
    /// outside of a-z or A-Z may count as a valid symbol.
    pub has_symbol: bool,
    /// missing_complexity: For LUDS validation, the number of complexity requirements that are missing from the
    /// password. Check the complexity fields to see which requirements are missing.
    pub missing_complexity: i32,
    /// missing_characters: For LUDS validation, this is the required length of the password that you've set
    /// minus the length of the password being checked. The user will need to add this many characters to the
    /// password to make it valid.
    pub missing_characters: i32,
}
/// MD5Config:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MD5Config {
    /// prepend_salt: The salt that should be prepended to the migrated password.
    pub prepend_salt: String,
    /// append_salt: The salt that should be appended to the migrated password.
    pub append_salt: String,
}
/// PBKDF2Config:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PBKDF2Config {
    /// salt: The salt value, which should be in a base64 encoded string form.
    pub salt: String,
    /// iteration_amount: The iteration amount.
    pub iteration_amount: i32,
    /// key_length: The key length, also known as the hash length.
    pub key_length: i32,
}
/// SHA1Config:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SHA1Config {
    /// prepend_salt: The salt that should be prepended to the migrated password.
    pub prepend_salt: String,
    /// append_salt: The salt that should be appended to the migrated password.
    pub append_salt: String,
}
/// ScryptConfig:
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ScryptConfig {
    /// salt: The salt value, which should be in a base64 encoded string form.
    pub salt: String,
    /// n_parameter: The N value, also known as the iterations count. It must be a power of two greater than 1
    /// and less than 262,145.
    ///   If your application's N parameter is larger than 262,144, please reach out to
    /// [support@stytch.com](mailto:support@stytch.com)
    pub n_parameter: i32,
    /// r_parameter: The r parameter, also known as the block size.
    pub r_parameter: i32,
    /// p_parameter: The p parameter, also known as the parallelism factor.
    pub p_parameter: i32,
    /// key_length: The key length, also known as the hash length.
    pub key_length: i32,
}
/// AuthenticateRequest: Request type for `Passwords.authenticate`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AuthenticateRequest {
    /// email: The email address of the end user.
    pub email: String,
    /// password: The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English
    /// characers, etc.
    pub password: String,
    /// session_token: The `session_token` associated with a User's existing Session.
    pub session_token: std::option::Option<String>,
    /// session_duration_minutes: Set the session lifetime to be this many minutes from now. This will start a
    /// new session if one doesn't already exist,
    ///   returning both an opaque `session_token` and `session_jwt` for this session. Remember that the
    /// `session_jwt` will have a fixed lifetime of
    ///   five minutes regardless of the underlying session duration, and will need to be refreshed over time.
    ///
    ///   This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
    ///
    ///   If a `session_token` or `session_jwt` is provided then a successful authentication will continue to
    /// extend the session this many minutes.
    ///
    ///   If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
    pub session_duration_minutes: std::option::Option<i32>,
    /// session_jwt: The `session_jwt` associated with a User's existing Session.
    pub session_jwt: std::option::Option<String>,
    /// session_custom_claims: Add a custom claims map to the Session being authenticated. Claims are only
    /// created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be
    /// included on the Session object and in the JWT. To update a key in an existing Session, supply a new
    /// value. To delete a key, supply a null value.
    ///
    ///   Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be
    /// ignored. Total custom claims size cannot exceed four kilobytes.
    pub session_custom_claims: std::option::Option<serde_json::Value>,
}
/// AuthenticateResponse: Response type for `Passwords.authenticate`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AuthenticateResponse {
    /// 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,
    /// user_id: The unique ID of the affected User.
    pub user_id: String,
    /// session_token: A secret token for a given Stytch Session.
    pub session_token: String,
    /// session_jwt: The JSON Web Token (JWT) for a given Stytch Session.
    pub session_jwt: String,
    /// user: The `user` object affected by this API call. See the
    /// [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
    pub user: User,
    /// status_code: The HTTP status code of the response. Stytch follows standard HTTP response status code
    /// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
    /// are server errors.
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
    /// session: If you initiate a Session, by including `session_duration_minutes` in your authenticate call,
    /// you'll receive a full Session object in the response.
    ///
    ///   See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
    ///
    pub session: std::option::Option<Session>,
}
/// CreateRequest: Request type for `Passwords.create`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct CreateRequest {
    /// email: The email address of the end user.
    pub email: String,
    /// password: The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English
    /// characers, etc.
    pub password: String,
    /// session_duration_minutes: Set the session lifetime to be this many minutes from now. This will start a
    /// new session if one doesn't already exist,
    ///   returning both an opaque `session_token` and `session_jwt` for this session. Remember that the
    /// `session_jwt` will have a fixed lifetime of
    ///   five minutes regardless of the underlying session duration, and will need to be refreshed over time.
    ///
    ///   This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
    ///
    ///   If a `session_token` or `session_jwt` is provided then a successful authentication will continue to
    /// extend the session this many minutes.
    ///
    ///   If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
    pub session_duration_minutes: std::option::Option<i32>,
    /// session_custom_claims: Add a custom claims map to the Session being authenticated. Claims are only
    /// created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be
    /// included on the Session object and in the JWT. To update a key in an existing Session, supply a new
    /// value. To delete a key, supply a null value.
    ///
    ///   Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be
    /// ignored. Total custom claims size cannot exceed four kilobytes.
    pub session_custom_claims: std::option::Option<serde_json::Value>,
    /// trusted_metadata: The `trusted_metadata` field contains an arbitrary JSON object of application-specific
    /// data. See the [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior
    /// details.
    pub trusted_metadata: std::option::Option<serde_json::Value>,
    /// untrusted_metadata: The `untrusted_metadata` field contains an arbitrary JSON object of
    /// application-specific data. Untrusted metadata can be edited by end users directly via the SDK, and
    /// **cannot be used to store critical information.** See the
    /// [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior details.
    pub untrusted_metadata: std::option::Option<serde_json::Value>,
    /// name: The name of the user. Each field in the name object is optional.
    pub name: std::option::Option<Name>,
}
/// CreateResponse: Response type for `Passwords.create`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateResponse {
    /// 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,
    /// user_id: The unique ID of the affected User.
    pub user_id: String,
    /// email_id: The unique ID of a specific email address.
    pub email_id: String,
    /// session_token: A secret token for a given Stytch Session.
    pub session_token: String,
    /// session_jwt: The JSON Web Token (JWT) for a given Stytch Session.
    pub session_jwt: String,
    /// user: The `user` object affected by this API call. See the
    /// [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
    pub user: User,
    /// status_code: The HTTP status code of the response. Stytch follows standard HTTP response status code
    /// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
    /// are server errors.
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
    /// session: If you initiate a Session, by including `session_duration_minutes` in your authenticate call,
    /// you'll receive a full Session object in the response.
    ///
    ///   See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
    ///
    pub session: std::option::Option<Session>,
}
/// MigrateRequest: Request type for `Passwords.migrate`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct MigrateRequest {
    /// email: The email address of the end user.
    pub email: String,
    /// hash: The password hash. For a Scrypt or PBKDF2 hash, the hash needs to be a base64 encoded string.
    pub hash: String,
    /// hash_type: The password hash used. Currently `bcrypt`, `scrypt`, `argon_2i`, `argon_2id`, `md_5`,
    /// `sha_1`, and `pbkdf_2` are supported.
    pub hash_type: MigrateRequestHashType,
    /// md_5_config: Optional parameters for MD-5 hash types.
    pub md_5_config: std::option::Option<MD5Config>,
    /// argon_2_config: Required parameters if the argon2 hex form, as opposed to the encoded form, is supplied.
    pub argon_2_config: std::option::Option<Argon2Config>,
    /// sha_1_config: Optional parameters for SHA-1 hash types.
    pub sha_1_config: std::option::Option<SHA1Config>,
    /// scrypt_config: Required parameters if the scrypt is not provided in a
    /// [PHC encoded form](https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#phc-string-format).
    pub scrypt_config: std::option::Option<ScryptConfig>,
    /// pbkdf_2_config: Required additional parameters for PBKDF2 hash keys.
    pub pbkdf_2_config: std::option::Option<PBKDF2Config>,
    /// trusted_metadata: The `trusted_metadata` field contains an arbitrary JSON object of application-specific
    /// data. See the [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior
    /// details.
    pub trusted_metadata: std::option::Option<serde_json::Value>,
    /// untrusted_metadata: The `untrusted_metadata` field contains an arbitrary JSON object of
    /// application-specific data. Untrusted metadata can be edited by end users directly via the SDK, and
    /// **cannot be used to store critical information.** See the
    /// [Metadata](https://stytch.com/docs/api/metadata) reference for complete field behavior details.
    pub untrusted_metadata: std::option::Option<serde_json::Value>,
    /// set_email_verified: Whether to set the user's email as verified. This is a dangerous field. Incorrect
    /// use may lead to users getting erroneously
    /// deduplicated into one user object. This flag should only be set if you can attest that the user owns the
    /// email address in question.
    /// Access to this field is restricted. To enable it, please send us a note at support@stytch.com.
    pub set_email_verified: std::option::Option<bool>,
    /// name: The name of the user. Each field in the name object is optional.
    pub name: std::option::Option<Name>,
}
/// MigrateResponse: Response type for `Passwords.migrate`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MigrateResponse {
    /// 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,
    /// user_id: The unique ID of the affected User.
    pub user_id: String,
    /// email_id: The unique ID of a specific email address.
    pub email_id: String,
    /// user_created: In `login_or_create` endpoints, this field indicates whether or not a User was just
    /// created.
    pub user_created: bool,
    /// user: The `user` object affected by this API call. See the
    /// [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
    pub user: User,
    /// status_code: The HTTP status code of the response. Stytch follows standard HTTP response status code
    /// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
    /// are server errors.
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
}
/// StrengthCheckRequest: Request type for `Passwords.strength_check`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct StrengthCheckRequest {
    /// password: The password for the user. Any UTF8 character is allowed, e.g. spaces, emojis, non-English
    /// characers, etc.
    pub password: String,
    /// email: The email address of the end user.
    pub email: std::option::Option<String>,
}
/// StrengthCheckResponse: Response type for `Passwords.strength_check`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct StrengthCheckResponse {
    /// 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,
    /// valid_password: Returns `true` if the password passes our password validation. We offer two validation
    /// options, [zxcvbn](https://stytch.com/docs/passwords#strength-requirements) is the default option which
    /// offers a high level of sophistication. We also offer
    /// [LUDS](https://stytch.com/docs/passwords#strength-requirements). If an email address is included in the
    /// call we also require that the password hasn't been compromised using built-in breach detection powered
    /// by [HaveIBeenPwned](https://haveibeenpwned.com/).
    pub valid_password: bool,
    /// score: The score of the password determined by [zxcvbn](https://github.com/dropbox/zxcvbn). Values will
    /// be between 1 and 4, a 3 or greater is required to pass validation.
    pub score: i32,
    /// breached_password: Returns `true` if the password has been breached. Powered by
    /// [HaveIBeenPwned](https://haveibeenpwned.com/).
    pub breached_password: bool,
    /// strength_policy: The strength policy type enforced, either `zxcvbn` or `luds`.
    pub strength_policy: String,
    /// breach_detection_on_create: Will return `true` if breach detection will be evaluated. By default this
    /// option is enabled. This option can be disabled by contacting
    /// [support@stytch.com](mailto:support@stytch.com?subject=Password%20strength%20configuration). If this
    /// value is `false` then `breached_password` will always be `false` as well.
    pub breach_detection_on_create: bool,
    /// status_code: The HTTP status code of the response. Stytch follows standard HTTP response status code
    /// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
    /// are server errors.
    #[serde(with = "http_serde::status_code")]
    pub status_code: http::StatusCode,
    /// feedback: Feedback for how to improve the password's strength
    /// [HaveIBeenPwned](https://haveibeenpwned.com/).
    pub feedback: std::option::Option<Feedback>,
}

#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub enum MigrateRequestHashType {
    #[serde(rename = "bcrypt")]
    #[default]
    Bcrypt,
    #[serde(rename = "md_5")]
    Md5,
    #[serde(rename = "argon_2i")]
    Argon2i,
    #[serde(rename = "argon_2id")]
    Argon2id,
    #[serde(rename = "sha_1")]
    Sha1,
    #[serde(rename = "scrypt")]
    Scrypt,
    #[serde(rename = "phpass")]
    Phpass,
    #[serde(rename = "pbkdf_2")]
    Pbkdf2,
}

pub struct Passwords {
    http_client: crate::client::Client,
    pub email: Email,
    pub existing_password: ExistingPassword,
    pub sessions: Sessions,
}

impl Passwords {
    pub fn new(http_client: crate::client::Client) -> Self {
        Self {
            http_client: http_client.clone(),
            email: Email::new(http_client.clone()),
            existing_password: ExistingPassword::new(http_client.clone()),
            sessions: Sessions::new(http_client.clone()),
        }
    }

    pub async fn create(&self, body: CreateRequest) -> crate::Result<CreateResponse> {
        let path = String::from("/v1/passwords");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
    pub async fn authenticate(
        &self,
        body: AuthenticateRequest,
    ) -> crate::Result<AuthenticateResponse> {
        let path = String::from("/v1/passwords/authenticate");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
    pub async fn strength_check(
        &self,
        body: StrengthCheckRequest,
    ) -> crate::Result<StrengthCheckResponse> {
        let path = String::from("/v1/passwords/strength_check");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
    pub async fn migrate(&self, body: MigrateRequest) -> crate::Result<MigrateResponse> {
        let path = String::from("/v1/passwords/migrate");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
}
