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

hub.exec.boto3.client.chime.create_channel_moderator
hub.exec.boto3.client.chime.delete_channel_moderator
hub.exec.boto3.client.chime.describe_channel_moderator
hub.exec.boto3.client.chime.list_channel_moderators
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, channel_arn: Text, channel_moderator_arn: Text, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Creates a new ChannelModerator. A channel moderator can:   Add and remove other members of the channel.   Add
    and remove other moderators of the channel.   Add and remove user bans for the channel.   Redact messages in the
    channel.   List messages in the channel.    The x-amz-chime-bearer request header is mandatory. Use the
    AppInstanceUserArn of the user that makes the API call as the value in the header.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_arn(Text): The ARN of the channel.
        channel_moderator_arn(Text): The ARN of the moderator.
        chime_bearer(Text, optional): The AppInstanceUserArn of the user that makes the API call. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

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

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.create_channel_moderator(
                ctx,
                
                
                **{"ChannelArn": channel_arn, "ChannelModeratorArn": channel_moderator_arn, "ChimeBearer": chime_bearer}
            )
            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.chime.describe_channel_moderator(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, channel_arn: Text, channel_moderator_arn: Text, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Deletes a channel moderator.  The x-amz-chime-bearer request header is mandatory. Use the AppInstanceUserArn of
    the user that makes the API call as the value in the header.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        channel_arn(Text): The ARN of the channel.
        channel_moderator_arn(Text): The ARN of the moderator being deleted.
        chime_bearer(Text, optional): The AppInstanceUserArn of the user that makes the API call. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.chime.channel_moderator.absent:
                - name: value
                - channel_arn: value
                - channel_moderator_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.channel_moderator.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.chime.describe_channel_moderator(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.delete_channel_moderator(
                ctx,
                
                
                **{"ChannelArn": channel_arn, "ChannelModeratorArn": channel_moderator_arn, "ChimeBearer": chime_bearer}
            )
            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.chime.describe_channel_moderator(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

