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

hub.exec.boto3.client.cloudfront.create_realtime_log_config
hub.exec.boto3.client.cloudfront.delete_realtime_log_config
hub.exec.boto3.client.cloudfront.get_realtime_log_config
hub.exec.boto3.client.cloudfront.list_realtime_log_configs
hub.exec.boto3.client.cloudfront.update_realtime_log_config
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, end_points: List, fields: List, sampling_rate: int)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a real-time log configuration. After you create a real-time log configuration, you can attach it to one
    or more cache behaviors to send real-time log data to the specified Amazon Kinesis data stream. For more
    information about real-time log configurations, see Real-time logs in the Amazon CloudFront Developer Guide.

    Args:
        name(Text): A unique name to identify this real-time log configuration.
        end_points(List): Contains information about the Amazon Kinesis data stream where you are sending real-time log
            data.
        fields(List): A list of fields to include in each real-time log record. For more information about fields, see
            Real-time log configuration fields in the Amazon CloudFront Developer Guide.
        sampling_rate(int): The sampling rate for this real-time log configuration. The sampling rate determines the
            percentage of viewer requests that are represented in the real-time log data. You must provide
            an integer between 1 and 100, inclusive.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.cloudfront.realtime_log_config.present:
                - name: value
                - end_points: value
                - fields: value
                - sampling_rate: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.cloudfront.realtime_log_config.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.cloudfront.get_realtime_log_config(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.cloudfront.create_realtime_log_config(
                ctx,
                
                
                **{"Name": name, "EndPoints": end_points, "Fields": fields, "SamplingRate": sampling_rate}
            )
            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.cloudfront.get_realtime_log_config(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text = None, arn: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a real-time log configuration. You cannot delete a real-time log configuration if it’s attached to a
    cache behavior. First update your distributions to remove the real-time log configuration from all cache
    behaviors, then delete the real-time log configuration. To delete a real-time log configuration, you can provide
    the configuration’s name or its Amazon Resource Name (ARN). You must provide at least one. If you provide both,
    CloudFront uses the name to identify the real-time log configuration to delete.

    Args:
        name(Text, optional): The name of the real-time log configuration to delete. Defaults to None.
        arn(Text, optional): The Amazon Resource Name (ARN) of the real-time log configuration to delete. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

