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

hub.exec.boto3.client.backup.create_backup_selection
hub.exec.boto3.client.backup.delete_backup_selection
hub.exec.boto3.client.backup.get_backup_selection
hub.exec.boto3.client.backup.list_backup_selections
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, backup_plan_id: Text, backup_selection: Dict, creator_request_id: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a JSON document that specifies a set of resources to assign to a backup plan. Resources can be included
    by specifying patterns for a ListOfTags and selected Resources.  For example, consider the following patterns:
    Resources: "arn:aws:ec2:region:account-id:volume/volume-id"     ConditionKey:"department"
    ConditionValue:"finance"   ConditionType:"StringEquals"     ConditionKey:"importance"
    ConditionValue:"critical"   ConditionType:"StringEquals"    Using these patterns would back up all Amazon
    Elastic Block Store (Amazon EBS) volumes that are tagged as "department=finance", "importance=critical", in
    addition to an EBS volume with the specified volume ID. Resources and conditions are additive in that all
    resources that match the pattern are selected. This shouldn't be confused with a logical AND, where all
    conditions must match. The matching patterns are logically put together using the OR operator. In other words,
    all patterns that match are selected for backup.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_plan_id(Text): Uniquely identifies the backup plan to be associated with the selection of resources.
        backup_selection(Dict): Specifies the body of a request to assign a set of resources to a backup plan.
        creator_request_id(Text, optional): A unique string that identifies the request and allows failed requests to be retried without the
            risk of running the operation twice. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

async def absent(hub, ctx, name: Text, backup_plan_id: Text, selection_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the resource selection associated with a backup plan that is specified by the SelectionId.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        backup_plan_id(Text): Uniquely identifies a backup plan.
        selection_id(Text): Uniquely identifies the body of a request to assign a set of resources to a backup plan.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

