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

hub.exec.boto3.client.ssm.create_ops_metadata
hub.exec.boto3.client.ssm.delete_ops_metadata
hub.exec.boto3.client.ssm.get_ops_metadata
hub.exec.boto3.client.ssm.list_ops_metadata
hub.exec.boto3.client.ssm.update_ops_metadata
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, resource_id: Text, metadata: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    If you create a new application in Application Manager, Amazon Web Services Systems Manager calls this API
    operation to specify information about the new application, including the application type.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        resource_id(Text): A resource ID for a new Application Manager application.
        metadata(Dict, optional): Metadata for a new Application Manager application. Defaults to None.
        tags(List, optional): Optional metadata that you assign to a resource. You can specify a maximum of five tags for an
            OpsMetadata object. Tags enable you to categorize a resource in different ways, such as by
            purpose, owner, or environment. For example, you might want to tag an OpsMetadata object to
            identify an environment or target Amazon Web Services Region. In this case, you could specify
            the following key-value pairs:    Key=Environment,Value=Production     Key=Region,Value=us-
            east-2. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.create_ops_metadata(
                ctx,
                
                
                **{"ResourceId": resource_id, "Metadata": metadata, "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.ssm.get_ops_metadata(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, ops_metadata_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete OpsMetadata related to an application.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        ops_metadata_arn(Text): The Amazon Resource Name (ARN) of an OpsMetadata Object to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

