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

hub.exec.boto3.client.servicecatalog.create_provisioning_artifact
hub.exec.boto3.client.servicecatalog.delete_provisioning_artifact
hub.exec.boto3.client.servicecatalog.describe_provisioning_artifact
hub.exec.boto3.client.servicecatalog.list_provisioning_artifacts
hub.exec.boto3.client.servicecatalog.update_provisioning_artifact
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, product_id: Text, parameters: Dict, idempotency_token: Text, accept_language: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a provisioning artifact (also known as a version) for the specified product. You cannot create a
    provisioning artifact for a product that was shared with you. The user or role that performs this operation must
    have the cloudformation:GetTemplate IAM policy permission. This policy permission is required when using the
    ImportFromPhysicalId template source in the information data section.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.
        product_id(Text): The product identifier.
        parameters(Dict): The configuration for the provisioning artifact.
        idempotency_token(Text): A unique identifier that you provide to ensure idempotency. If multiple requests differ only by
            the idempotency token, the same response is returned for each repeated request.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.servicecatalog.provisioning_artifact.present:
                - name: value
                - product_id: value
                - parameters: value
                - idempotency_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.provisioning_artifact.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.servicecatalog.describe_provisioning_artifact(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.create_provisioning_artifact(
                ctx,
                
                
                **{"AcceptLanguage": accept_language, "ProductId": product_id, "Parameters": parameters, "IdempotencyToken": idempotency_token}
            )
            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.servicecatalog.describe_provisioning_artifact(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, product_id: Text, provisioning_artifact_id: Text, accept_language: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified provisioning artifact (also known as a version) for the specified product. You cannot
    delete a provisioning artifact associated with a product that was shared with you. You cannot delete the last
    provisioning artifact for a product, because a product must have at least one provisioning artifact.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.
        product_id(Text): The product identifier.
        provisioning_artifact_id(Text): The identifier of the provisioning artifact.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.servicecatalog.provisioning_artifact.absent:
                - name: value
                - product_id: value
                - provisioning_artifact_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.provisioning_artifact.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.servicecatalog.describe_provisioning_artifact(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.delete_provisioning_artifact(
                ctx,
                
                
                **{"AcceptLanguage": accept_language, "ProductId": product_id, "ProvisioningArtifactId": provisioning_artifact_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.servicecatalog.describe_provisioning_artifact(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

