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

hub.exec.boto3.client.backup.create_backup_plan
hub.exec.boto3.client.backup.delete_backup_plan
hub.exec.boto3.client.backup.get_backup_plan
hub.exec.boto3.client.backup.list_backup_plans
hub.exec.boto3.client.backup.update_backup_plan
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, backup_plan: Dict, backup_plan_tags: Dict = None, creator_request_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a backup plan using a backup plan name and backup rules. A backup plan is a document that contains
    information that AWS Backup uses to schedule tasks that create recovery points for resources. If you call
    CreateBackupPlan with a plan that already exists, an AlreadyExistsException is returned.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_plan(Dict): Specifies the body of a backup plan. Includes a BackupPlanName and one or more sets of Rules.
        backup_plan_tags(Dict, optional): To help organize your resources, you can assign your own metadata to the resources that you
            create. Each tag is a key-value pair. The specified tags are assigned to all backups created
            with this plan. Defaults to None.
        creator_request_id(Text, optional): Identifies the request and allows failed requests to be retried without the risk of running the
            operation twice. If the request includes a CreatorRequestId that matches an existing backup
            plan, that plan is returned. This parameter is optional. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.backup.create_backup_plan(
                ctx,
                
                
                **{"BackupPlan": backup_plan, "BackupPlanTags": backup_plan_tags, "CreatorRequestId": creator_request_id}
            )
            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.backup.get_backup_plan(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, backup_plan_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a backup plan. A backup plan can only be deleted after all associated selections of resources have been
    deleted. Deleting a backup plan deletes the current version of a backup plan. Previous versions, if any, will
    still exist.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_plan_id(Text): Uniquely identifies a backup plan.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

