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

hub.exec.boto3.client.sagemaker.create_workforce
hub.exec.boto3.client.sagemaker.delete_workforce
hub.exec.boto3.client.sagemaker.describe_workforce
hub.exec.boto3.client.sagemaker.list_workforces
hub.exec.boto3.client.sagemaker.update_workforce
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, workforce_name: Text, cognito_config: Dict = None, oidc_config: Dict = None, source_ip_config: Dict = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Use this operation to create a workforce. This operation will return an error if a workforce already exists in
    the Amazon Web Services Region that you specify. You can only create one workforce in each Amazon Web Services
    Region per Amazon Web Services account. If you want to create a new workforce in an Amazon Web Services Region
    where a workforce already exists, use the API operation to delete the existing workforce and then use
    CreateWorkforce to create a new workforce. To create a private workforce using Amazon Cognito, you must specify
    a Cognito user pool in CognitoConfig. You can also create an Amazon Cognito workforce using the Amazon SageMaker
    console. For more information, see  Create a Private Workforce (Amazon Cognito). To create a private workforce
    using your own OIDC Identity Provider (IdP), specify your IdP configuration in OidcConfig. Your OIDC IdP must
    support groups because groups are used by Ground Truth and Amazon A2I to create work teams. For more
    information, see  Create a Private Workforce (OIDC IdP).

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        cognito_config(Dict, optional): Use this parameter to configure an Amazon Cognito private workforce. A single Cognito workforce
            is created using and corresponds to a single  Amazon Cognito user pool. Do not use OidcConfig if
            you specify values for CognitoConfig. Defaults to None.
        oidc_config(Dict, optional): Use this parameter to configure a private workforce using your own OIDC Identity Provider. Do
            not use CognitoConfig if you specify values for OidcConfig. Defaults to None.
        source_ip_config(Dict, optional): A list of IP address ranges (CIDRs). Used to create an allow list of IP addresses for a private
            workforce. Workers will only be able to login to their worker portal from an IP address within
            this range. By default, a workforce isn't restricted to specific IP addresses. Defaults to None.
        workforce_name(Text): The name of the private workforce.
        tags(List, optional): An array of key-value pairs that contain metadata to help you categorize and organize our
            workforce. Each tag consists of a key and a value, both of which you define. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.sagemaker.create_workforce(
                ctx,
                
                
                **{"CognitoConfig": cognito_config, "OidcConfig": oidc_config, "SourceIpConfig": source_ip_config, "WorkforceName": workforce_name, "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.sagemaker.describe_workforce(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, workforce_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Use this operation to delete a workforce. If you want to create a new workforce in an Amazon Web Services Region
    where a workforce already exists, use this operation to delete the existing workforce and then use to create a
    new workforce.  If a private workforce contains one or more work teams, you must use the operation to delete all
    work teams before you delete the workforce. If you try to delete a workforce that contains one or more work
    teams, you will recieve a ResourceInUse error.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        workforce_name(Text): The name of the workforce.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

