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

hub.exec.boto3.client.servicecatalog.copy_product
hub.exec.boto3.client.servicecatalog.create_product
hub.exec.boto3.client.servicecatalog.delete_product
hub.exec.boto3.client.servicecatalog.describe_product
hub.exec.boto3.client.servicecatalog.provision_product
hub.exec.boto3.client.servicecatalog.search_products
hub.exec.boto3.client.servicecatalog.update_product
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, owner: Text, product_type: Text, provisioning_artifact_parameters: Dict, idempotency_token: Text, accept_language: Text = None, description: Text = None, distributor: Text = None, support_description: Text = None, support_email: Text = None, support_url: Text = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a product. A delegated admin is authorized to invoke this command. 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): The name of the product.
        accept_language(Text, optional): The language code.    en - English (default)    jp - Japanese    zh - Chinese. Defaults to None.
        owner(Text): The owner of the product.
        description(Text, optional): The description of the product. Defaults to None.
        distributor(Text, optional): The distributor of the product. Defaults to None.
        support_description(Text, optional): The support information about the product. Defaults to None.
        support_email(Text, optional): The contact email for product support. Defaults to None.
        support_url(Text, optional): The contact URL for product support.  ^https?:\/\// / is the pattern used to validate
            SupportUrl. Defaults to None.
        product_type(Text): The type of product.
        tags(List, optional): One or more tags. Defaults to None.
        provisioning_artifact_parameters(Dict): The configuration of 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.product.present:
                - name: value
                - owner: value
                - product_type: value
                - provisioning_artifact_parameters: value
                - idempotency_token: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.servicecatalog.product.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_product(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.create_product(
                ctx,
                
                
                **{"Name": name, "AcceptLanguage": accept_language, "Owner": owner, "Description": description, "Distributor": distributor, "SupportDescription": support_description, "SupportEmail": support_email, "SupportUrl": support_url, "ProductType": product_type, "Tags": tags, "ProvisioningArtifactParameters": provisioning_artifact_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_product(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, id_: Text, accept_language: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified product. You cannot delete a product if it was shared with you or is associated with a
    portfolio. A delegated admin is authorized to invoke this command.

    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.
        id_(Text): The product identifier.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

