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

hub.exec.boto3.client.fis.create_experiment_template
hub.exec.boto3.client.fis.delete_experiment_template
hub.exec.boto3.client.fis.get_experiment_template
hub.exec.boto3.client.fis.list_experiment_templates
hub.exec.boto3.client.fis.update_experiment_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, client_token: Text, description: Text, stop_conditions: List, actions: Dict, role_arn: Text, targets: Dict = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an experiment template.  To create a template, specify the following information:     Targets: A target
    can be a specific resource in your AWS environment, or one or more resources that match criteria that you
    specify, for example, resources that have specific tags.    Actions: The actions to carry out on the target. You
    can specify multiple actions, the duration of each action, and when to start each action during an experiment.
    Stop conditions: If a stop condition is triggered while an experiment is running, the experiment is
    automatically stopped. You can define a stop condition as a CloudWatch alarm.   For more information, see the
    AWS Fault Injection Simulator User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        client_token(Text): Unique, case-sensitive identifier that you provide to ensure the idempotency of the request.
        description(Text): A description for the experiment template. Can contain up to 64 letters (A-Z and a-z).
        stop_conditions(List): The stop conditions.
        targets(Dict, optional): The targets for the experiment. Defaults to None.
        actions(Dict): The actions for the experiment.
        role_arn(Text): The Amazon Resource Name (ARN) of an IAM role that grants the AWS FIS service permission to
            perform service actions on your behalf.
        tags(Dict, optional): The tags to apply to the experiment template. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.fis.experiment_template.present:
                - name: value
                - client_token: value
                - description: value
                - stop_conditions: value
                - actions: value
                - role_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.fis.experiment_template.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.fis.get_experiment_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.fis.create_experiment_template(
                ctx,
                
                
                **{"clientToken": client_token, "description": description, "stopConditions": stop_conditions, "targets": targets, "actions": actions, "roleArn": role_arn, "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.fis.get_experiment_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified experiment template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        id_(Text): The ID of the experiment template.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

