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

hub.exec.boto3.client.apigateway.create_base_path_mapping
hub.exec.boto3.client.apigateway.delete_base_path_mapping
hub.exec.boto3.client.apigateway.get_base_path_mappings
hub.exec.boto3.client.apigateway.update_base_path_mapping
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, domain_name: Text, rest_api_id: Text, base_path: Text = None, stage: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new BasePathMapping resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): [Required] The domain name of the BasePathMapping resource to create.
        base_path(Text, optional): The base path name that callers of the API must provide as part of the URL after the domain
            name. This value must be unique for all of the mappings across a single API. Specify '(none)' if
            you do not want callers to specify a base path name after the domain name. Defaults to None.
        rest_api_id(Text): [Required] The string identifier of the associated RestApi.
        stage(Text, optional): The name of the API's stage that you want to use for this mapping. Specify '(none)' if you want
            callers to explicitly specify the stage name after any base path name. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_base_path_mapping(
                ctx,
                
                
                **{"domainName": domain_name, "basePath": base_path, "restApiId": rest_api_id, "stage": stage}
            )
            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_base_path_mappings(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, domain_name: Text, base_path: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the BasePathMapping resource.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        domain_name(Text): [Required] The domain name of the BasePathMapping resource to delete.
        base_path(Text): [Required] The base path name of the BasePathMapping resource to delete. To specify an empty
            base path, set this parameter to '(none)'.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.delete_base_path_mapping(
                ctx,
                
                
                **{"domainName": domain_name, "basePath": base_path}
            )
            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_base_path_mappings(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

