# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Optional
from datetime import datetime
from typing_extensions import Literal

from .logging import Logging
from ..._models import BaseModel

__all__ = ["SetConfigRule", "ActionParameters", "ActionParametersAutominify", "ExposedCredentialCheck", "Ratelimit"]


class ActionParametersAutominify(BaseModel):
    """Which file extensions to minify automatically."""

    css: Optional[bool] = None
    """Whether to minify CSS files."""

    html: Optional[bool] = None
    """Whether to minify HTML files."""

    js: Optional[bool] = None
    """Whether to minify JavaScript files."""


class ActionParameters(BaseModel):
    """The parameters configuring the rule's action."""

    automatic_https_rewrites: Optional[bool] = None
    """Whether to enable Automatic HTTPS Rewrites."""

    autominify: Optional[ActionParametersAutominify] = None
    """Which file extensions to minify automatically."""

    bic: Optional[bool] = None
    """Whether to enable Browser Integrity Check (BIC)."""

    disable_apps: Optional[Literal[True]] = None
    """Whether to disable Cloudflare Apps."""

    disable_pay_per_crawl: Optional[Literal[True]] = None
    """Whether to disable Pay Per Crawl."""

    disable_rum: Optional[Literal[True]] = None
    """Whether to disable Real User Monitoring (RUM)."""

    disable_zaraz: Optional[Literal[True]] = None
    """Whether to disable Zaraz."""

    email_obfuscation: Optional[bool] = None
    """Whether to enable Email Obfuscation."""

    fonts: Optional[bool] = None
    """Whether to enable Cloudflare Fonts."""

    hotlink_protection: Optional[bool] = None
    """Whether to enable Hotlink Protection."""

    mirage: Optional[bool] = None
    """Whether to enable Mirage."""

    opportunistic_encryption: Optional[bool] = None
    """Whether to enable Opportunistic Encryption."""

    polish: Optional[Literal["off", "lossless", "lossy", "webp"]] = None
    """The Polish level to configure."""

    request_body_buffering: Optional[Literal["none", "standard", "full"]] = None
    """The request body buffering mode."""

    response_body_buffering: Optional[Literal["none", "standard"]] = None
    """The response body buffering mode."""

    rocket_loader: Optional[bool] = None
    """Whether to enable Rocket Loader."""

    security_level: Optional[Literal["off", "essentially_off", "low", "medium", "high", "under_attack"]] = None
    """The Security Level to configure."""

    server_side_excludes: Optional[bool] = None
    """Whether to enable Server-Side Excludes."""

    ssl: Optional[Literal["off", "flexible", "full", "strict", "origin_pull"]] = None
    """The SSL level to configure."""

    sxg: Optional[bool] = None
    """Whether to enable Signed Exchanges (SXG)."""


class ExposedCredentialCheck(BaseModel):
    """Configuration for exposed credential checking."""

    password_expression: str
    """An expression that selects the password used in the credentials check."""

    username_expression: str
    """An expression that selects the user ID used in the credentials check."""


class Ratelimit(BaseModel):
    """An object configuring the rule's rate limit behavior."""

    characteristics: List[str]
    """
    Characteristics of the request on which the rate limit counter will be
    incremented.
    """

    period: int
    """Period in seconds over which the counter is being incremented."""

    counting_expression: Optional[str] = None
    """An expression that defines when the rate limit counter should be incremented.

    It defaults to the same as the rule's expression.
    """

    mitigation_timeout: Optional[int] = None
    """
    Period of time in seconds after which the action will be disabled following its
    first execution.
    """

    requests_per_period: Optional[int] = None
    """
    The threshold of requests per period after which the action will be executed for
    the first time.
    """

    requests_to_origin: Optional[bool] = None
    """Whether counting is only performed when an origin is reached."""

    score_per_period: Optional[int] = None
    """
    The score threshold per period for which the action will be executed the first
    time.
    """

    score_response_header_name: Optional[str] = None
    """
    A response header name provided by the origin, which contains the score to
    increment rate limit counter with.
    """


class SetConfigRule(BaseModel):
    last_updated: datetime
    """The timestamp of when the rule was last modified."""

    version: str
    """The version of the rule."""

    id: Optional[str] = None
    """The unique ID of the rule."""

    action: Optional[Literal["set_config"]] = None
    """The action to perform when the rule matches."""

    action_parameters: Optional[ActionParameters] = None
    """The parameters configuring the rule's action."""

    categories: Optional[List[str]] = None
    """The categories of the rule."""

    description: Optional[str] = None
    """An informative description of the rule."""

    enabled: Optional[bool] = None
    """Whether the rule should be executed."""

    exposed_credential_check: Optional[ExposedCredentialCheck] = None
    """Configuration for exposed credential checking."""

    expression: Optional[str] = None
    """The expression defining which traffic will match the rule."""

    logging: Optional[Logging] = None
    """An object configuring the rule's logging behavior."""

    ratelimit: Optional[Ratelimit] = None
    """An object configuring the rule's rate limit behavior."""

    ref: Optional[str] = None
    """The reference of the rule (the rule's ID by default)."""
