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

hub.exec.boto3.client.servicecatalog.create_provisioned_product_plan
hub.exec.boto3.client.servicecatalog.delete_provisioned_product_plan
hub.exec.boto3.client.servicecatalog.describe_provisioned_product_plan
hub.exec.boto3.client.servicecatalog.execute_provisioned_product_plan
hub.exec.boto3.client.servicecatalog.list_provisioned_product_plans
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, plan_name: Text, plan_type: Text, product_id: Text, provisioned_product_name: Text, provisioning_artifact_id: Text, idempotency_token: Text, accept_language: Text = None, notification_arns: List = None, path_id: Text = None, provisioning_parameters: List = None, tags: List = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a plan. A plan includes the list of resources to be created (when provisioning a new product) or
    modified (when updating a provisioned product) when the plan is executed. You can create one plan per
    provisioned product. To create a plan for an existing provisioned product, the product status must be AVAILBLE
    or TAINTED. To view the resource changes in the change set, use DescribeProvisionedProductPlan. To create or
    modify the provisioned product, use ExecuteProvisionedProductPlan.

    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.
        plan_name(Text): The name of the plan.
        plan_type(Text): The plan type.
        notification_arns(List, optional): Passed to CloudFormation. The SNS topic ARNs to which to publish stack-related events. Defaults to None.
        path_id(Text, optional): The path identifier of the product. This value is optional if the product has a default path,
            and required if the product has more than one path. To list the paths for a product, use
            ListLaunchPaths. Defaults to None.
        product_id(Text): The product identifier.
        provisioned_product_name(Text): A user-friendly name for the provisioned product. This value must be unique for the AWS account
            and cannot be updated after the product is provisioned.
        provisioning_artifact_id(Text): The identifier of the provisioning artifact.
        provisioning_parameters(List, optional): Parameters specified by the administrator that are required for provisioning the product. Defaults to None.
        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.
        tags(List, optional): One or more tags. If the plan is for an existing provisioned product, the product must have a
            RESOURCE_UPDATE constraint with TagUpdatesOnProvisionedProduct set to ALLOWED to allow tag
            updates. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.servicecatalog.create_provisioned_product_plan(
                ctx,
                
                
                **{"AcceptLanguage": accept_language, "PlanName": plan_name, "PlanType": plan_type, "NotificationArns": notification_arns, "PathId": path_id, "ProductId": product_id, "ProvisionedProductName": provisioned_product_name, "ProvisioningArtifactId": provisioning_artifact_id, "ProvisioningParameters": provisioning_parameters, "IdempotencyToken": idempotency_token, "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.servicecatalog.describe_provisioned_product_plan(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, plan_id: Text, accept_language: Text = None, ignore_errors: bool = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the specified plan.

    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.
        plan_id(Text): The plan identifier.
        ignore_errors(bool, optional): If set to true, AWS Service Catalog stops managing the specified provisioned product even if it
            cannot delete the underlying resources. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

