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

hub.exec.boto3.client.apigateway.delete_gateway_response
hub.exec.boto3.client.apigateway.get_gateway_responses
hub.exec.boto3.client.apigateway.put_gateway_response
hub.exec.boto3.client.apigateway.update_gateway_response
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, rest_api_id: Text, response_type: Text, status_code: Text = None, response_parameters: Dict = None, response_templates: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a customization of a GatewayResponse of a specified response type and status code on the 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.
        response_type(Text): [Required] The response type of the associated GatewayResponse. Valid values are
            ACCESS_DENIEDAPI_CONFIGURATION_ERRORAUTHORIZER_FAILURE AUTHORIZER_CONFIGURATION_ERRORBAD_REQUEST
            _PARAMETERSBAD_REQUEST_BODYDEFAULT_4XXDEFAULT_5XXEXPIRED_TOKENINVALID_SIGNATUREINTEGRATION_FAILU
            REINTEGRATION_TIMEOUTINVALID_API_KEYMISSING_AUTHENTICATION_TOKEN
            QUOTA_EXCEEDEDREQUEST_TOO_LARGERESOURCE_NOT_FOUNDTHROTTLEDUNAUTHORIZEDUNSUPPORTED_MEDIA_TYPE.
        status_code(Text, optional): The HTTP status code of the GatewayResponse. Defaults to None.
        response_parameters(Dict, optional): Response parameters (paths, query strings and headers) of the GatewayResponse as a string-to-
            string map of key-value pairs. Defaults to None.
        response_templates(Dict, optional): Response templates of the GatewayResponse as a string-to-string map of key-value pairs. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigateway.gateway_response.present:
                - name: value
                - rest_api_id: value
                - response_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.gateway_response.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_gateway_responses(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.put_gateway_response(
                ctx,
                
                
                **{"restApiId": rest_api_id, "responseType": response_type, "statusCode": status_code, "responseParameters": response_parameters, "responseTemplates": response_templates}
            )
            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_gateway_responses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, rest_api_id: Text, response_type: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Clears any customization of a GatewayResponse of a specified response type on the given RestApi and resets it
    with the default settings.

    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.
        response_type(Text): [Required] The response type of the associated GatewayResponse. Valid values are
            ACCESS_DENIEDAPI_CONFIGURATION_ERRORAUTHORIZER_FAILURE AUTHORIZER_CONFIGURATION_ERRORBAD_REQUEST
            _PARAMETERSBAD_REQUEST_BODYDEFAULT_4XXDEFAULT_5XXEXPIRED_TOKENINVALID_SIGNATUREINTEGRATION_FAILU
            REINTEGRATION_TIMEOUTINVALID_API_KEYMISSING_AUTHENTICATION_TOKEN
            QUOTA_EXCEEDEDREQUEST_TOO_LARGERESOURCE_NOT_FOUNDTHROTTLEDUNAUTHORIZEDUNSUPPORTED_MEDIA_TYPE.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.apigateway.gateway_response.absent:
                - name: value
                - rest_api_id: value
                - response_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigateway.gateway_response.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_gateway_responses(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.delete_gateway_response(
                ctx,
                
                
                **{"restApiId": rest_api_id, "responseType": response_type}
            )
            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_gateway_responses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

