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

hub.exec.boto3.client.quicksight.create_analysis
hub.exec.boto3.client.quicksight.delete_analysis
hub.exec.boto3.client.quicksight.describe_analysis
hub.exec.boto3.client.quicksight.list_analyses
hub.exec.boto3.client.quicksight.restore_analysis
hub.exec.boto3.client.quicksight.search_analyses
hub.exec.boto3.client.quicksight.update_analysis
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, aws_account_id: Text, analysis_id: Text, source_entity: Dict, parameters: Dict = None, permissions: List = None, theme_arn: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an analysis in Amazon QuickSight.

    Args:
        name(Text): A descriptive name for the analysis that you're creating. This name displays for the analysis in
            the QuickSight console.
        aws_account_id(Text): The ID of the Amazon Web Services account; where you are creating an analysis.
        analysis_id(Text): The ID for the analysis that you're creating. This ID displays in the URL of the analysis.
        parameters(Dict, optional): The parameter names and override values that you want to use. An analysis can have any parameter
            type, and some parameters might accept multiple values. Defaults to None.
        permissions(List, optional): A structure that describes the principals and the resource-level permissions on an analysis. You
            can use the Permissions structure to grant permissions by providing a list of Identity and
            Access Management (IAM) action information for each principal listed by Amazon Resource Name
            (ARN).  To specify no permissions, omit Permissions. Defaults to None.
        source_entity(Dict): A source entity to use for the analysis that you're creating. This metadata structure contains
            details that describe a source template and one or more datasets.
        theme_arn(Text, optional): The ARN for the theme to apply to the analysis that you're creating. To see the theme in the
            QuickSight console, make sure that you have access to it. Defaults to None.
        tags(List, optional): Contains a map of the key-value pairs for the resource tag or tags assigned to the analysis. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.create_analysis(
                ctx,
                
                
                **{"Name": name, "AwsAccountId": aws_account_id, "AnalysisId": analysis_id, "Parameters": parameters, "Permissions": permissions, "SourceEntity": source_entity, "ThemeArn": theme_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.quicksight.describe_analysis(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, aws_account_id: Text, analysis_id: Text, recovery_window_in_days: int = None, force_delete_without_recovery: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an analysis from Amazon QuickSight. You can optionally include a recovery window during which you can
    restore the analysis. If you don't specify a recovery window value, the operation defaults to 30 days.
    QuickSight attaches a DeletionTime stamp to the response that specifies the end of the recovery window. At the
    end of the recovery window, QuickSight deletes the analysis permanently. At any time before recovery window
    ends, you can use the RestoreAnalysis API operation to remove the DeletionTime stamp and cancel the deletion of
    the analysis. The analysis remains visible in the API until it's deleted, so you can describe it but you can't
    make a template from it. An analysis that's scheduled for deletion isn't accessible in the QuickSight console.
    To access it in the console, restore it. Deleting an analysis doesn't delete the dashboards that you publish
    from it.

    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; where you want to delete an analysis.
        analysis_id(Text): The ID of the analysis that you're deleting.
        recovery_window_in_days(int, optional): A value that specifies the number of days that QuickSight waits before it deletes the analysis.
            You can't use this parameter with the ForceDeleteWithoutRecovery option in the same API call.
            The default value is 30. Defaults to None.
        force_delete_without_recovery(bool, optional): This option defaults to the value NoForceDeleteWithoutRecovery. To immediately delete the
            analysis, add the ForceDeleteWithoutRecovery option. You can't restore an analysis after it's
            deleted. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.quicksight.delete_analysis(
                ctx,
                
                
                **{"AwsAccountId": aws_account_id, "AnalysisId": analysis_id, "RecoveryWindowInDays": recovery_window_in_days, "ForceDeleteWithoutRecovery": force_delete_without_recovery}
            )
            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_analysis(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

