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

hub.exec.boto3.client.iam.create_service_specific_credential
hub.exec.boto3.client.iam.delete_service_specific_credential
hub.exec.boto3.client.iam.list_service_specific_credentials
hub.exec.boto3.client.iam.reset_service_specific_credential
hub.exec.boto3.client.iam.update_service_specific_credential
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, user_name: Text, service_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Generates a set of credentials consisting of a user name and password that can be used to access the service
    specified in the request. These credentials are generated by IAM, and can be used only for the specified
    service.  You can have a maximum of two sets of service-specific credentials for each supported service per
    user. You can create service-specific credentials for CodeCommit and Amazon Keyspaces (for Apache Cassandra).
    You can reset the password to a new service-generated value by calling ResetServiceSpecificCredential. For more
    information about service-specific credentials, see Using IAM with CodeCommit: Git credentials, SSH keys, and
    Amazon Web Services access keys in the IAM User Guide.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text): The name of the IAM user that is to be associated with the credentials. The new service-specific
            credentials have the same permissions as the associated user except that they can be used only
            to access the specified service. This parameter allows (through its regex pattern) a string of
            characters consisting of upper and lowercase alphanumeric characters with no spaces. You can
            also include any of the following characters: _+=,.@-.
        service_name(Text): The name of the Amazon Web Services service that is to be associated with the credentials. The
            service you specify here is the only service that can be accessed using these credentials.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.iam.service_specific_credential.present:
                - name: value
                - user_name: value
                - service_name: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.iam.service_specific_credential.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.iam.list_service_specific_credentials(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.create_service_specific_credential(
                ctx,
                
                
                **{"UserName": user_name, "ServiceName": service_name}
            )
            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.iam.list_service_specific_credentials(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, service_specific_credential_id: Text, user_name: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified service-specific credential.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        user_name(Text, optional): The name of the IAM user associated with the service-specific credential. If this value is not
            specified, then the operation assumes the user whose credentials are used to call the operation.
            This parameter allows (through its regex pattern) a string of characters consisting of upper and
            lowercase alphanumeric characters with no spaces. You can also include any of the following
            characters: _+=,.@-. Defaults to None.
        service_specific_credential_id(Text): The unique identifier of the service-specific credential. You can get this value by calling
            ListServiceSpecificCredentials. This parameter allows (through its regex pattern) a string of
            characters that can consist of any upper or lowercased letter or digit.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.iam.delete_service_specific_credential(
                ctx,
                
                
                **{"UserName": user_name, "ServiceSpecificCredentialId": service_specific_credential_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.iam.list_service_specific_credentials(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

