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

hub.exec.boto3.client.iot.create_role_alias
hub.exec.boto3.client.iot.delete_role_alias
hub.exec.boto3.client.iot.describe_role_alias
hub.exec.boto3.client.iot.update_role_alias
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, role_alias: Text, role_arn: Text, credential_duration_seconds: int = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a role alias.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        role_alias(Text): The role alias that points to a role ARN. This allows you to change the role without having to
            update the device.
        role_arn(Text): The role ARN.
        credential_duration_seconds(int, optional): How long (in seconds) the credentials will be valid. Defaults to None.
        tags(List, optional): Metadata which can be used to manage the role alias.  For URI Request parameters use format:
            ...key1=value1&key2=value2... For the CLI command-line parameter use format: &&tags
            "key1=value1&key2=value2..." For the cli-input-json file use format: "tags":
            "key1=value1&key2=value2...". Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iot.create_role_alias(
                ctx,
                
                
                **{"roleAlias": role_alias, "roleArn": role_arn, "credentialDurationSeconds": credential_duration_seconds, "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.iot.describe_role_alias(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, role_alias: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a role alias

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        role_alias(Text): The role alias to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

