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

hub.exec.boto3.client.personalize.create_campaign
hub.exec.boto3.client.personalize.delete_campaign
hub.exec.boto3.client.personalize.describe_campaign
hub.exec.boto3.client.personalize.list_campaigns
hub.exec.boto3.client.personalize.update_campaign
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, solution_version_arn: Text, min_provisioned_tps: int = None, campaign_config: Dict = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a campaign by deploying a solution version. When a client calls the GetRecommendations and
    GetPersonalizedRanking APIs, a campaign is specified in the request.  Minimum Provisioned TPS and Auto-Scaling
    A transaction is a single GetRecommendations or GetPersonalizedRanking call. Transactions per second (TPS) is
    the throughput and unit of billing for Amazon Personalize. The minimum provisioned TPS (minProvisionedTPS)
    specifies the baseline throughput provisioned by Amazon Personalize, and thus, the minimum billing charge.   If
    your TPS increases beyond minProvisionedTPS, Amazon Personalize auto-scales the provisioned capacity up and
    down, but never below minProvisionedTPS. There's a short time delay while the capacity is increased that might
    cause loss of transactions. The actual TPS used is calculated as the average requests/second within a 5-minute
    window. You pay for maximum of either the minimum provisioned TPS or the actual TPS. We recommend starting with
    a low minProvisionedTPS, track your usage using Amazon CloudWatch metrics, and then increase the
    minProvisionedTPS as necessary.  Status  A campaign can be in one of the following states:   CREATE PENDING >
    CREATE IN_PROGRESS > ACTIVE -or- CREATE FAILED   DELETE PENDING > DELETE IN_PROGRESS   To get the campaign
    status, call DescribeCampaign.  Wait until the status of the campaign is ACTIVE before asking the campaign for
    recommendations.   Related APIs     ListCampaigns     DescribeCampaign     UpdateCampaign     DeleteCampaign

    Args:
        name(Text): A name for the new campaign. The campaign name must be unique within your account.
        solution_version_arn(Text): The Amazon Resource Name (ARN) of the solution version to deploy.
        min_provisioned_tps(int, optional): Specifies the requested minimum provisioned transactions (recommendations) per second that
            Amazon Personalize will support. Defaults to None.
        campaign_config(Dict, optional): The configuration details of a campaign. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.personalize.campaign.present:
                - name: value
                - solution_version_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.personalize.campaign.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.personalize.describe_campaign(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.personalize.create_campaign(
                ctx,
                
                
                **{"Name": name, "solutionVersionArn": solution_version_arn, "minProvisionedTPS": min_provisioned_tps, "campaignConfig": campaign_config}
            )
            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.personalize.describe_campaign(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, campaign_arn: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a campaign by deleting the solution deployment. The solution that the campaign is based on is not
    deleted and can be redeployed when needed. A deleted campaign can no longer be specified in a GetRecommendations
    request. For more information on campaigns, see CreateCampaign.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        campaign_arn(Text): The Amazon Resource Name (ARN) of the campaign to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

