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

hub.exec.boto3.client.quicksight.create_template
hub.exec.boto3.client.quicksight.delete_template
hub.exec.boto3.client.quicksight.describe_template
hub.exec.boto3.client.quicksight.list_templates
hub.exec.boto3.client.quicksight.update_template
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, aws_account_id: Text, template_id: Text, source_entity: Dict, name: Text = None, permissions: List = None, tags: List = None, version_description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a template from an existing Amazon QuickSight analysis or template. You can use the resulting template
    to create a dashboard. A template is an entity in QuickSight that encapsulates the metadata required to create
    an analysis and that you can use to create s dashboard. A template adds a layer of abstraction by using
    placeholders to replace the dataset associated with the analysis. You can use templates to create dashboards by
    replacing dataset placeholders with datasets that follow the same schema that was used to create the source
    analysis and template.

    Args:
        name(Text, optional): A display name for the template. Defaults to None.
        aws_account_id(Text): The ID for the Amazon Web Services account; that the group is in. Currently, you use the ID for
            the Amazon Web Services account; that contains your Amazon QuickSight account.
        template_id(Text): An ID for the template that you want to create. This template is unique per Amazon Web Services
            Region; in each Amazon Web Services account;.
        permissions(List, optional): A list of resource permissions to be set on the template. Defaults to None.
        source_entity(Dict): The entity that you are using as a source when you create the template. In SourceEntity, you
            specify the type of object you're using as source: SourceTemplate for a template or
            SourceAnalysis for an analysis. Both of these require an Amazon Resource Name (ARN). For
            SourceTemplate, specify the ARN of the source template. For SourceAnalysis, specify the ARN of
            the source analysis. The SourceTemplate ARN can contain any Amazon Web Services account; and any
            QuickSight-supported Amazon Web Services Region;.  Use the DataSetReferences entity within
            SourceTemplate or SourceAnalysis to list the replacement datasets for the placeholders listed in
            the original. The schema in each dataset must match its placeholder.
        tags(List, optional): Contains a map of the key-value pairs for the resource tag or tags assigned to the resource. Defaults to None.
        version_description(Text, optional): A description of the current template version being created. This API operation creates the
            first version of the template. Every time UpdateTemplate is called, a new version is created.
            Each version of the template maintains a description of the version in the VersionDescription
            field. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.quicksight.template.present:
                - aws_account_id: value
                - template_id: value
                - source_entity: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.quicksight.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.quicksight.describe_template(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.create_template(
                ctx,
                
                
                **{"Name": name, "AwsAccountId": aws_account_id, "TemplateId": template_id, "Permissions": permissions, "SourceEntity": source_entity, "Tags": tags, "VersionDescription": version_description}
            )
            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.quicksight.describe_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, aws_account_id: Text, template_id: Text, version_number: int = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a template.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        aws_account_id(Text): The ID of the Amazon Web Services account; that contains the template that you're deleting.
        template_id(Text): An ID for the template you want to delete.
        version_number(int, optional): Specifies the version of the template that you want to delete. If you don't provide a version
            number, DeleteTemplate deletes all versions of the template. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.delete_template(
                ctx,
                
                
                **{"AwsAccountId": aws_account_id, "TemplateId": template_id, "VersionNumber": version_number}
            )
            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.quicksight.describe_template(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

