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

hub.exec.boto3.client.eks.create_addon
hub.exec.boto3.client.eks.delete_addon
hub.exec.boto3.client.eks.describe_addon
hub.exec.boto3.client.eks.list_addons
hub.exec.boto3.client.eks.update_addon
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, cluster_name: Text, addon_name: Text, addon_version: Text = None, service_account_role_arn: Text = None, resolve_conflicts: Text = None, client_request_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Amazon EKS add-on. Amazon EKS add-ons help to automate the provisioning and lifecycle management of
    common operational software for Amazon EKS clusters. Amazon EKS add-ons can only be used with Amazon EKS
    clusters running version 1.18 with platform version eks.3 or later because add-ons rely on the Server-side Apply
    Kubernetes feature, which is only available in Kubernetes 1.18 and later.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_name(Text): The name of the cluster to create the add-on for.
        addon_name(Text): The name of the add-on. The name must match one of the names returned by  DescribeAddonVersions
            .
        addon_version(Text, optional): The version of the add-on. The version must match one of the versions returned by
            DescribeAddonVersions . Defaults to None.
        service_account_role_arn(Text, optional): The Amazon Resource Name (ARN) of an existing IAM role to bind to the add-on's service account.
            The role must be assigned the IAM permissions required by the add-on. If you don't specify an
            existing IAM role, then the add-on uses the permissions assigned to the node IAM role. For more
            information, see Amazon EKS node IAM role in the Amazon EKS User Guide.  To specify an existing
            IAM role, you must have an IAM OpenID Connect (OIDC) provider created for your cluster. For more
            information, see Enabling IAM roles for service accounts on your cluster in the Amazon EKS User
            Guide. Defaults to None.
        resolve_conflicts(Text, optional): How to resolve parameter value conflicts when migrating an existing add-on to an Amazon EKS add-
            on. Defaults to None.
        client_request_token(Text, optional): A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. Defaults to None.
        tags(Dict, optional): The metadata to apply to the cluster to assist with categorization and organization. Each tag
            consists of a key and an optional value, both of which you define. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.eks.addon.present:
                - name: value
                - cluster_name: value
                - addon_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.eks.addon.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.eks.describe_addon(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.eks.create_addon(
                ctx,
                
                
                **{"clusterName": cluster_name, "addonName": addon_name, "addonVersion": addon_version, "serviceAccountRoleArn": service_account_role_arn, "resolveConflicts": resolve_conflicts, "clientRequestToken": client_request_token, "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.eks.describe_addon(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cluster_name: Text, addon_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Delete an Amazon EKS add-on. When you remove the add-on, it will also be deleted from the cluster. You can
    always manually start an add-on on the cluster using the Kubernetes API.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_name(Text): The name of the cluster to delete the add-on from.
        addon_name(Text): The name of the add-on. The name must match one of the names returned by  ListAddons .

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.eks.addon.absent:
                - name: value
                - cluster_name: value
                - addon_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.eks.addon.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.eks.describe_addon(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.eks.delete_addon(
                ctx,
                
                
                **{"clusterName": cluster_name, "addonName": addon_name}
            )
            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.eks.describe_addon(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

