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

hub.exec.boto3.client.ssm.associate_ops_item_related_item
hub.exec.boto3.client.ssm.disassociate_ops_item_related_item
hub.exec.boto3.client.ssm.list_ops_item_related_items
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, ops_item_id: Text, association_type: Text, resource_type: Text, resource_uri: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Associates a related resource to a Systems Manager OpsCenter OpsItem. For example, you can associate an Incident
    Manager incident or analysis with an OpsItem. Incident Manager is a capability of Amazon Web Services Systems
    Manager.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        ops_item_id(Text): The ID of the OpsItem to which you want to associate a resource as a related item.
        association_type(Text): The type of association that you want to create between an OpsItem and a resource. OpsCenter
            supports IsParentOf and RelatesTo association types.
        resource_type(Text): The type of resource that you want to associate with an OpsItem. OpsCenter supports the
            following types:  AWS::SSMIncidents::IncidentRecord: an Incident Manager incident. Incident
            Manager is a capability of Amazon Web Services Systems Manager.  AWS::SSM::Document: a Systems
            Manager (SSM) document.
        resource_uri(Text): The Amazon Resource Name (ARN) of the Amazon Web Services resource that you want to associate
            with the OpsItem.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.ssm.ops_item_related_item.present:
                - name: value
                - ops_item_id: value
                - association_type: value
                - resource_type: value
                - resource_uri: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm.ops_item_related_item.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.ssm.list_ops_item_related_items(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.associate_ops_item_related_item(
                ctx,
                
                
                **{"OpsItemId": ops_item_id, "AssociationType": association_type, "ResourceType": resource_type, "ResourceUri": resource_uri}
            )
            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.ssm.list_ops_item_related_items(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, ops_item_id: Text, association_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the association between an OpsItem and a related resource. For example, this API operation can delete an
    Incident Manager incident from an OpsItem. Incident Manager is a capability of Amazon Web Services Systems
    Manager.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        ops_item_id(Text): The ID of the OpsItem for which you want to delete an association between the OpsItem and a
            related resource.
        association_id(Text): The ID of the association for which you want to delete an association between the OpsItem and a
            related resource.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.ssm.ops_item_related_item.absent:
                - name: value
                - ops_item_id: value
                - association_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.ssm.ops_item_related_item.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.ssm.list_ops_item_related_items(name)

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

