"""
Autogenerated state module using `pop-create-idem <https://gitlab.com/saltstack/pop/pop-create-idem>`__

hub.exec.boto3.client.apigateway.create_request_validator
hub.exec.boto3.client.apigateway.delete_request_validator
hub.exec.boto3.client.apigateway.get_request_validators
hub.exec.boto3.client.apigateway.update_request_validator
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, rest_api_id: Text, name: Text = None, validate_request_body: bool = None, validate_request_parameters: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a ReqeustValidator of a given RestApi.

    Args:
        name(Text, optional): The name of the to-be-created RequestValidator. Defaults to None.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.
        validate_request_body(bool, optional): A Boolean flag to indicate whether to validate request body according to the configured model
            schema for the method (true) or not (false). Defaults to None.
        validate_request_parameters(bool, optional): A Boolean flag to indicate whether to validate request parameters, true, or not false. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigateway.request_validator.present:
                - rest_api_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.request_validator.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    
    before = await hub.exec.boto3.client.apigateway.get_request_validators(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_request_validator(
                ctx,
                
                
                **{"Name": name, "restApiId": rest_api_id, "validateRequestBody": validate_request_body, "validateRequestParameters": validate_request_parameters}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            ret["comment"] = f"Created '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    
    # TODO perform other modifications as needed here
    ...

    after = await hub.exec.boto3.client.apigateway.get_request_validators(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rest_api_id: Text, request_validator_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a RequestValidator of a given RestApi.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.
        request_validator_id(Text): [Required] The identifier of the RequestValidator to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.apigateway.request_validator.absent:
                - name: value
                - rest_api_id: value
                - request_validator_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.request_validator.id(
        ctx,
        jmes_path=name
    )
    if ret["status"]:
        # name is now the first id that matched the JMES search path
        name = ret["ret"]
    

    

    before = await hub.exec.boto3.client.apigateway.get_request_validators(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.delete_request_validator(
                ctx,
                
                
                **{"restApiId": rest_api_id, "requestValidatorId": request_validator_id}
            )
            result["result"] = ret["status"]
            if not result["result"]:
                result["comment"] = ret["comment"]
                return result
            result["comment"] = f"Deleted '{name}'"
        except hub.tool.boto3.exception.ClientError as e:
            result["comment"] = f"{e.__class__.__name__}: {e}"

    

    after = await hub.exec.boto3.client.apigateway.get_request_validators(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

