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

hub.exec.boto3.client.apigatewayv2.create_api
hub.exec.boto3.client.apigatewayv2.delete_api
hub.exec.boto3.client.apigatewayv2.export_api
hub.exec.boto3.client.apigatewayv2.get_api
hub.exec.boto3.client.apigatewayv2.import_api
hub.exec.boto3.client.apigatewayv2.reimport_api
hub.exec.boto3.client.apigatewayv2.update_api
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, protocol_type: Text, api_key_selection_expression: Text = None, cors_configuration: Dict = None, credentials_arn: Text = None, description: Text = None, disable_schema_validation: bool = None, disable_execute_api_endpoint: bool = None, route_key: Text = None, route_selection_expression: Text = None, tags: Dict = None, target: Text = None, version: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Api resource.

    Args:
        name(Text): The name of the API.
        api_key_selection_expression(Text, optional): An API key selection expression. Supported only for WebSocket APIs. See API Key Selection
            Expressions. Defaults to None.
        cors_configuration(Dict, optional): A CORS configuration. Supported only for HTTP APIs. See Configuring CORS for more information. Defaults to None.
        credentials_arn(Text, optional): This property is part of quick create. It specifies the credentials required for the
            integration, if any. For a Lambda integration, three options are available. To specify an IAM
            Role for API Gateway to assume, use the role's Amazon Resource Name (ARN). To require that the
            caller's identity be passed through from the request, specify arn:aws:iam::*:user/*. To use
            resource-based permissions on supported AWS services, specify null. Currently, this property is
            not used for HTTP integrations. Supported only for HTTP APIs. Defaults to None.
        description(Text, optional): The description of the API. Defaults to None.
        disable_schema_validation(bool, optional): Avoid validating models when creating a deployment. Supported only for WebSocket APIs. Defaults to None.
        disable_execute_api_endpoint(bool, optional): Specifies whether clients can invoke your API by using the default execute-api endpoint. By
            default, clients can invoke your API with the default https://{api_id}.execute-
            api.{region}.amazonaws.com endpoint. To require that clients use a custom domain name to invoke
            your API, disable the default endpoint. Defaults to None.
        protocol_type(Text): The API protocol.
        route_key(Text, optional): This property is part of quick create. If you don't specify a routeKey, a default route of
            $default is created. The $default route acts as a catch-all for any request made to your API,
            for a particular stage. The $default route key can't be modified. You can add routes after
            creating the API, and you can update the route keys of additional routes. Supported only for
            HTTP APIs. Defaults to None.
        route_selection_expression(Text, optional): The route selection expression for the API. For HTTP APIs, the routeSelectionExpression must be
            ${request.method} ${request.path}. If not provided, this will be the default for HTTP APIs. This
            property is required for WebSocket APIs. Defaults to None.
        tags(Dict, optional): The collection of tags. Each tag element is associated with a given resource. Defaults to None.
        target(Text, optional): This property is part of quick create. Quick create produces an API with an integration, a
            default catch-all route, and a default stage which is configured to automatically deploy
            changes. For HTTP integrations, specify a fully qualified URL. For Lambda integrations, specify
            a function ARN. The type of the integration will be HTTP_PROXY or AWS_PROXY, respectively.
            Supported only for HTTP APIs. Defaults to None.
        version(Text, optional): A version identifier for the API. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.apigatewayv2.api.present:
                - name: value
                - protocol_type: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.apigatewayv2.api.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_api(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigatewayv2.create_api(
                ctx,
                
                
                **{"Name": name, "ApiKeySelectionExpression": api_key_selection_expression, "CorsConfiguration": cors_configuration, "CredentialsArn": credentials_arn, "Description": description, "DisableSchemaValidation": disable_schema_validation, "DisableExecuteApiEndpoint": disable_execute_api_endpoint, "ProtocolType": protocol_type, "RouteKey": route_key, "RouteSelectionExpression": route_selection_expression, "Tags": tags, "Target": target, "Version": version}
            )
            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_api(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

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

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

