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

hub.exec.boto3.client.cognito_idp.create_identity_provider
hub.exec.boto3.client.cognito_idp.delete_identity_provider
hub.exec.boto3.client.cognito_idp.describe_identity_provider
hub.exec.boto3.client.cognito_idp.list_identity_providers
hub.exec.boto3.client.cognito_idp.update_identity_provider
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_pool_id: Text, provider_name: Text, provider_type: Text, provider_details: Dict, attribute_mapping: Dict = None, idp_identifiers: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates an identity provider for a user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_pool_id(Text): The user pool ID.
        provider_name(Text): The identity provider name.
        provider_type(Text): The identity provider type.
        provider_details(Dict): The identity provider details. The following list describes the provider detail keys for each
            identity provider type.   For Google and Login with Amazon:   client_id   client_secret
            authorize_scopes     For Facebook:   client_id   client_secret   authorize_scopes   api_version
            For Sign in with Apple:   client_id   team_id   key_id   private_key   authorize_scopes     For
            OIDC providers:   client_id   client_secret   attributes_request_method   oidc_issuer
            authorize_scopes   authorize_url if not available from discovery URL specified by oidc_issuer
            key    token_url if not available from discovery URL specified by oidc_issuer key
            attributes_url if not available from discovery URL specified by oidc_issuer key    jwks_uri if
            not available from discovery URL specified by oidc_issuer key      For SAML providers:
            MetadataFile OR MetadataURL   IDPSignout optional.
        attribute_mapping(Dict, optional): A mapping of identity provider attributes to standard and custom user pool attributes. Defaults to None.
        idp_identifiers(List, optional): A list of identity provider identifiers. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cognito_idp.identity_provider.present:
                - name: value
                - user_pool_id: value
                - provider_name: value
                - provider_type: value
                - provider_details: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cognito_idp.identity_provider.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.cognito_idp.describe_identity_provider(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cognito_idp.create_identity_provider(
                ctx,
                
                
                **{"UserPoolId": user_pool_id, "ProviderName": provider_name, "ProviderType": provider_type, "ProviderDetails": provider_details, "AttributeMapping": attribute_mapping, "IdpIdentifiers": idp_identifiers}
            )
            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.cognito_idp.describe_identity_provider(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, user_pool_id: Text, provider_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes an identity provider for a user pool.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_pool_id(Text): The user pool ID.
        provider_name(Text): The identity provider name.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.cognito_idp.identity_provider.absent:
                - name: value
                - user_pool_id: value
                - provider_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cognito_idp.identity_provider.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.cognito_idp.describe_identity_provider(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.cognito_idp.delete_identity_provider(
                ctx,
                
                
                **{"UserPoolId": user_pool_id, "ProviderName": provider_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.cognito_idp.describe_identity_provider(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

