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

hub.exec.boto3.client.eks.create_fargate_profile
hub.exec.boto3.client.eks.delete_fargate_profile
hub.exec.boto3.client.eks.describe_fargate_profile
hub.exec.boto3.client.eks.list_fargate_profiles
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, fargate_profile_name: Text, cluster_name: Text, pod_execution_role_arn: Text, subnets: List = None, selectors: List = None, client_request_token: Text = None, tags: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an Fargate profile for your Amazon EKS cluster. You must have at least one Fargate profile in a cluster
    to be able to run pods on Fargate. The Fargate profile allows an administrator to declare which pods run on
    Fargate and specify which pods run on which Fargate profile. This declaration is done through the profile’s
    selectors. Each profile can have up to five selectors that contain a namespace and labels. A namespace is
    required for every selector. The label field consists of multiple optional key-value pairs. Pods that match the
    selectors are scheduled on Fargate. If a to-be-scheduled pod matches any of the selectors in the Fargate
    profile, then that pod is run on Fargate. When you create a Fargate profile, you must specify a pod execution
    role to use with the pods that are scheduled with the profile. This role is added to the cluster's Kubernetes
    Role Based Access Control (RBAC) for authorization so that the kubelet that is running on the Fargate
    infrastructure can register with your Amazon EKS cluster so that it can appear in your cluster as a node. The
    pod execution role also provides IAM permissions to the Fargate infrastructure to allow read access to Amazon
    ECR image repositories. For more information, see Pod Execution Role in the Amazon EKS User Guide. Fargate
    profiles are immutable. However, you can create a new updated profile to replace an existing profile and then
    delete the original after the updated profile has finished creating. If any Fargate profiles in a cluster are in
    the DELETING status, you must wait for that Fargate profile to finish deleting before you can create any other
    profiles in that cluster. For more information, see Fargate Profile in the Amazon EKS User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        fargate_profile_name(Text): The name of the Fargate profile.
        cluster_name(Text): The name of the Amazon EKS cluster to apply the Fargate profile to.
        pod_execution_role_arn(Text): The Amazon Resource Name (ARN) of the pod execution role to use for pods that match the
            selectors in the Fargate profile. The pod execution role allows Fargate infrastructure to
            register with your cluster as a node, and it provides read access to Amazon ECR image
            repositories. For more information, see Pod Execution Role in the Amazon EKS User Guide.
        subnets(List, optional): The IDs of subnets to launch your pods into. At this time, pods running on Fargate are not
            assigned public IP addresses, so only private subnets (with no direct route to an Internet
            Gateway) are accepted for this parameter. Defaults to None.
        selectors(List, optional): The selectors to match for pods to use this Fargate profile. Each selector must have an
            associated namespace. Optionally, you can also specify labels for a namespace. You may specify
            up to five selectors in a Fargate profile. Defaults to None.
        client_request_token(Text, optional): 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 Fargate profile to assist with categorization and organization.
            Each tag consists of a key and an optional value, both of which you define. Fargate profile tags
            do not propagate to any other resources associated with the Fargate profile, such as the pods
            that are scheduled with it. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.eks.create_fargate_profile(
                ctx,
                
                
                **{"fargateProfileName": fargate_profile_name, "clusterName": cluster_name, "podExecutionRoleArn": pod_execution_role_arn, "subnets": subnets, "selectors": selectors, "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_fargate_profile(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, cluster_name: Text, fargate_profile_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an Fargate profile. When you delete a Fargate profile, any pods running on Fargate that were created
    with the profile are deleted. If those pods match another Fargate profile, then they are scheduled on Fargate
    with that profile. If they no longer match any Fargate profiles, then they are not scheduled on Fargate and they
    may remain in a pending state. Only one Fargate profile in a cluster can be in the DELETING status at a time.
    You must wait for a Fargate profile to finish deleting before you can delete any other profiles in that cluster.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cluster_name(Text): The name of the Amazon EKS cluster associated with the Fargate profile to delete.
        fargate_profile_name(Text): The name of the Fargate profile to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

