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

hub.exec.boto3.client.apigateway.create_api_key
hub.exec.boto3.client.apigateway.delete_api_key
hub.exec.boto3.client.apigateway.get_api_keys
hub.exec.boto3.client.apigateway.import_api_keys
hub.exec.boto3.client.apigateway.update_api_key
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text = None, description: Text = None, enabled: bool = None, generate_distinct_id: bool = None, value: Text = None, stage_keys: List = None, customer_id: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create an ApiKey resource.  AWS CLI

    Args:
        name(Text, optional): The name of the ApiKey. Defaults to None.
        description(Text, optional): The description of the ApiKey. Defaults to None.
        enabled(bool, optional): Specifies whether the ApiKey can be used by callers. Defaults to None.
        generate_distinct_id(bool, optional): Specifies whether (true) or not (false) the key identifier is distinct from the created API key
            value. This parameter is deprecated and should not be used. Defaults to None.
        value(Text, optional): Specifies a value of the API key. Defaults to None.
        stage_keys(List, optional): DEPRECATED FOR USAGE PLANS - Specifies stages associated with the API key. Defaults to None.
        customer_id(Text, optional): An AWS Marketplace customer identifier , when integrating with the AWS SaaS Marketplace. Defaults to None.
        tags(Dict, optional): The key-value map of strings. The valid character set is [a-zA-Z+-=._:/]. The tag key can be up
            to 128 characters and must not start with aws:. The tag value can be up to 256 characters. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.apigateway.create_api_key(
                ctx,
                
                
                **{"Name": name, "description": description, "enabled": enabled, "generateDistinctId": generate_distinct_id, "value": value, "stageKeys": stage_keys, "customerId": customer_id, "tags": tags}
            )
            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_api_keys(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

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

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        api_key(Text): [Required] The identifier of the ApiKey resource to be deleted.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

