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

hub.exec.boto3.client.es.associate_package
hub.exec.boto3.client.es.create_package
hub.exec.boto3.client.es.delete_package
hub.exec.boto3.client.es.describe_packages
hub.exec.boto3.client.es.dissociate_package
hub.exec.boto3.client.es.update_package
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, package_name: Text, package_type: Text, package_source: Dict, package_description: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Create a package for use with Amazon ES domains.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        package_name(Text): Unique identifier for the package.
        package_type(Text): Type of package. Currently supports only TXT-DICTIONARY.
        package_description(Text, optional): Description of the package. Defaults to None.
        package_source(Dict): The customer S3 location PackageSource for importing the package.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.es.package.present:
                - name: value
                - package_name: value
                - package_type: value
                - package_source: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.es.package.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.es.describe_packages(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.es.create_package(
                ctx,
                
                
                **{"PackageName": package_name, "PackageType": package_type, "PackageDescription": package_description, "PackageSource": package_source}
            )
            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.es.describe_packages(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, package_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete the package.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        package_id(Text): Internal ID of the package that you want to delete. Use DescribePackages to find this value.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

