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

hub.exec.boto3.client.apigatewayv2.create_integration_response
hub.exec.boto3.client.apigatewayv2.delete_integration_response
hub.exec.boto3.client.apigatewayv2.get_integration_responses
hub.exec.boto3.client.apigatewayv2.update_integration_response
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, api_id: Text, integration_id: Text, integration_response_key: Text, content_handling_strategy: Text = None, response_parameters: Dict = None, response_templates: Dict = None, template_selection_expression: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an IntegrationResponses.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API identifier.
        content_handling_strategy(Text, optional): Specifies how to handle response payload content type conversions. Supported values are
            CONVERT_TO_BINARY and CONVERT_TO_TEXT, with the following behaviors: CONVERT_TO_BINARY: Converts
            a response payload from a Base64-encoded string to the corresponding binary blob.
            CONVERT_TO_TEXT: Converts a response payload from a binary blob to a Base64-encoded string. If
            this property is not defined, the response payload will be passed through from the integration
            response to the route response or method response without modification. Defaults to None.
        integration_id(Text): The integration ID.
        integration_response_key(Text): The integration response key.
        response_parameters(Dict, optional): A key-value map specifying response parameters that are passed to the method response from the
            backend. The key is a method response header parameter name and the mapped value is an
            integration response header value, a static value enclosed within a pair of single quotes, or a
            JSON expression from the integration response body. The mapping key must match the pattern of
            method.response.header.{name}, where {name} is a valid and unique header name. The mapped non-
            static value must match the pattern of integration.response.header.{name} or
            integration.response.body.{JSON-expression}, where {name} is a valid and unique response header
            name and {JSON-expression} is a valid JSON expression without the $ prefix. Defaults to None.
        response_templates(Dict, optional): The collection of response templates for the integration response as a string-to-string map of
            key-value pairs. Response templates are represented as a key/value map, with a content-type as
            the key and a template as the value. Defaults to None.
        template_selection_expression(Text, optional): The template selection expression for the integration response. Supported only for WebSocket
            APIs. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigatewayv2.integration_response.present:
                - name: value
                - api_id: value
                - integration_id: value
                - integration_response_key: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigatewayv2.integration_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.apigatewayv2.get_integration_responses(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigatewayv2.create_integration_response(
                ctx,
                
                
                **{"ApiId": api_id, "ContentHandlingStrategy": content_handling_strategy, "IntegrationId": integration_id, "IntegrationResponseKey": integration_response_key, "ResponseParameters": response_parameters, "ResponseTemplates": response_templates, "TemplateSelectionExpression": template_selection_expression}
            )
            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.apigatewayv2.get_integration_responses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, api_id: Text, integration_id: Text, integration_response_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an IntegrationResponses.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_id(Text): The API identifier.
        integration_id(Text): The integration ID.
        integration_response_id(Text): The integration response ID.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.apigatewayv2.integration_response.absent:
                - name: value
                - api_id: value
                - integration_id: value
                - integration_response_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigatewayv2.integration_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.apigatewayv2.get_integration_responses(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigatewayv2.delete_integration_response(
                ctx,
                
                
                **{"ApiId": api_id, "IntegrationId": integration_id, "IntegrationResponseId": integration_response_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.apigatewayv2.get_integration_responses(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

