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

hub.exec.boto3.client.ssm.delete_inventory
hub.exec.boto3.client.ssm.get_inventory
hub.exec.boto3.client.ssm.put_inventory
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, instance_id: Text, items: List)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Bulk update custom inventory items on one more instance. The request adds an inventory item, if it doesn't
    already exist, or updates an inventory item, if it does exist.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        instance_id(Text): An instance ID where you want to add or update inventory items.
        items(List): The inventory items that you want to add or update on instances.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.put_inventory(
                ctx,
                
                
                **{"InstanceId": instance_id, "Items": items}
            )
            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_inventory(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, type_name: Text, schema_delete_option: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete a custom inventory type or the data associated with a custom Inventory type. Deleting a custom inventory
    type is also referred to as deleting a custom inventory schema.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        type_name(Text): The name of the custom inventory type for which you want to delete either all previously
            collected data or the inventory type itself.
        schema_delete_option(Text, optional): Use the SchemaDeleteOption to delete a custom inventory type (schema). If you don't choose this
            option, the system only deletes existing inventory data associated with the custom inventory
            type. Choose one of the following options: DisableSchema: If you choose this option, the system
            ignores all inventory data for the specified version, and any earlier versions. To enable this
            schema again, you must call the PutInventory operation for a version greater than the disabled
            version. DeleteSchema: This option deletes the specified custom type from the Inventory service.
            You can recreate the schema later, if you want. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.ssm.delete_inventory(
                ctx,
                DryRun=ctx.test,
                ClientToken=name,
                **{"TypeName": type_name, "SchemaDeleteOption": schema_delete_option}
            )
            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_inventory(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

