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

use crate::consumer::fraud::Rule;
use crate::consumer::fraud::RuleAction;
use serde::{Deserialize, Serialize};

/// ListRequest: Request type for `Rules.list`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct ListRequest {
    /// cursor: The `cursor` field allows you to paginate through your results. Each result array is limited to
    /// 100 results. If your query returns more than 100 results, you will need to paginate the responses using
    /// the `cursor`. If you receive a response that includes a non-null `next_cursor`, repeat the request with
    /// the `next_cursor` value set to the `cursor` field to retrieve the next page of results. Continue to make
    /// requests until the `next_cursor` in the response is null.
    pub cursor: std::option::Option<String>,
    /// limit: The number of results to return per page. The default limit is 10. A maximum of 100 results can
    /// be returned by a single get request. If the total size of your result set is greater than one page size,
    /// you must paginate the response. See the `cursor` field.
    pub limit: std::option::Option<i32>,
}
/// ListResponse: Response type for `Rules.list`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ListResponse {
    /// 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,
    /// next_cursor: The `next_cursor` string is returned when your result contains more than one page of
    /// results. This value is passed into your next request in the `cursor` field.
    pub next_cursor: String,
    /// rules: A list of rules for the project
    pub rules: std::vec::Vec<Rule>,
    /// 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,
}
/// SetRequest: Request type for `Rules.set`.
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct SetRequest {
    /// action: The action that should be returned by a fingerprint lookup for that identifier with a
    /// `RULE_MATCH` reason. The following values are valid: `ALLOW`, `BLOCK`, `CHALLENGE`, or `NONE`. For
    /// country codes, `ALLOW` actions are not allowed. If a `NONE` action is specified, it will clear the
    /// stored rule.
    pub action: RuleAction,
    /// visitor_id: The visitor ID we want to set a rule for. Only one identifier can be specified in the
    /// request.
    pub visitor_id: std::option::Option<String>,
    /// browser_id: The browser ID we want to set a rule for. Only one identifier can be specified in the
    /// request.
    pub browser_id: std::option::Option<String>,
    /// visitor_fingerprint: The visitor fingerprint we want to set a rule for. Only one identifier can be
    /// specified in the request.
    pub visitor_fingerprint: std::option::Option<String>,
    /// browser_fingerprint: The browser fingerprint we want to set a rule for. Only one identifier can be
    /// specified in the request.
    pub browser_fingerprint: std::option::Option<String>,
    /// hardware_fingerprint: The hardware fingerprint we want to set a rule for. Only one identifier can be
    /// specified in the request.
    pub hardware_fingerprint: std::option::Option<String>,
    /// network_fingerprint: The network fingerprint we want to set a rule for. Only one identifier can be
    /// specified in the request.
    pub network_fingerprint: std::option::Option<String>,
    /// expires_in_minutes: The number of minutes until this rule expires. If no `expires_in_minutes` is
    /// specified, then the rule is kept permanently.
    pub expires_in_minutes: std::option::Option<i32>,
    /// description: An optional description for the rule.
    pub description: std::option::Option<String>,
    /// cidr_block: The CIDR block we want to set a rule for. You may pass either an IP address or a CIDR block.
    /// The CIDR block prefix must be between 16 and 32, inclusive. If an end user's IP address is within this
    /// CIDR block, this rule will be applied. Only one identifier can be specified in the request.
    pub cidr_block: std::option::Option<String>,
    /// country_code: The country code we want to set a rule for. The country code must be a valid ISO 3166-1
    /// alpha-2 code. You may not set `ALLOW` rules for country codes. Only one identifier can be specified in
    /// the request.
    pub country_code: std::option::Option<String>,
    /// asn: The ASN we want to set a rule for. The ASN must be the string representation of an integer between
    /// 0 and 4294967295, inclusive. Only one identifier can be specified in the request.
    pub asn: std::option::Option<String>,
}
/// SetResponse: Response type for `Rules.set`.
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SetResponse {
    /// 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,
    /// action: The action that will be returned for the specified identifier.
    pub action: RuleAction,
    /// 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,
    /// visitor_id: The visitor ID that a rule was set for.
    pub visitor_id: std::option::Option<String>,
    /// browser_id: The browser ID that a rule was set for.
    pub browser_id: std::option::Option<String>,
    /// visitor_fingerprint: The visitor fingerprint that a rule was set for.
    pub visitor_fingerprint: std::option::Option<String>,
    /// browser_fingerprint: The browser fingerprint that a rule was set for.
    pub browser_fingerprint: std::option::Option<String>,
    /// hardware_fingerprint: The hardware fingerprint that a rule was set for.
    pub hardware_fingerprint: std::option::Option<String>,
    /// network_fingerprint: The network fingerprint that a rule was set for.
    pub network_fingerprint: std::option::Option<String>,
    /// expires_at: The timestamp when the rule expires. Values conform to the RFC 3339 standard and are
    /// expressed in UTC, e.g. `2021-12-29T12:33:09Z`.
    pub expires_at: std::option::Option<chrono::DateTime<chrono::Utc>>,
    /// cidr_block: The CIDR block that a rule was set for. If an end user's IP address is within this CIDR
    /// block, this rule will be applied.
    pub cidr_block: std::option::Option<String>,
    /// country_code: The country code that a rule was set for.
    pub country_code: std::option::Option<String>,
    /// asn: The ASN that a rule was set for.
    pub asn: std::option::Option<String>,
}

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

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

    pub async fn set(&self, body: SetRequest) -> crate::Result<SetResponse> {
        let path = String::from("/v1/rules/set");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
    pub async fn list(&self, body: ListRequest) -> crate::Result<ListResponse> {
        let path = String::from("/v1/rules/list");
        self.http_client
            .send(crate::Request {
                method: http::Method::POST,
                path,
                body,
            })
            .await
    }
}
