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

hub.exec.boto3.client.config.delete_delivery_channel
hub.exec.boto3.client.config.describe_delivery_channels
hub.exec.boto3.client.config.put_delivery_channel
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, delivery_channel: Dict)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a delivery channel object to deliver configuration information to an Amazon S3 bucket and Amazon SNS
    topic. Before you can create a delivery channel, you must create a configuration recorder. You can use this
    action to change the Amazon S3 bucket or an Amazon SNS topic of the existing delivery channel. To change the
    Amazon S3 bucket or an Amazon SNS topic, call this action and specify the changed values for the S3 bucket and
    the SNS topic. If you specify a different value for either the S3 bucket or the SNS topic, this action will keep
    the existing value for the parameter that is not changed.  You can have only one delivery channel per region in
    your account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        delivery_channel(Dict): The configuration delivery channel object that delivers the configuration information to an
            Amazon S3 bucket and to an Amazon SNS topic.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.config.put_delivery_channel(
                ctx,
                
                
                **{"DeliveryChannel": delivery_channel}
            )
            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.config.describe_delivery_channels(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, delivery_channel_name: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes the delivery channel. Before you can delete the delivery channel, you must stop the configuration
    recorder by using the StopConfigurationRecorder action.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        delivery_channel_name(Text): The name of the delivery channel to delete.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

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

