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

hub.exec.boto3.client.chime.create_channel_membership
hub.exec.boto3.client.chime.delete_channel_membership
hub.exec.boto3.client.chime.describe_channel_membership
hub.exec.boto3.client.chime.list_channel_memberships
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, channel_arn: Text, member_arn: Text, type_: Text, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds a user to a channel. The InvitedBy response field is derived from the request header. A channel member can:
    List messages   Send messages   Receive messages   Edit their own messages   Leave the channel   Privacy
    settings impact this action as follows:   Public Channels: You do not need to be a member to list messages, but
    you must be a member to send messages.   Private Channels: You must be a member to list or send messages.    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 to which you're adding users.
        member_arn(Text): The ARN of the member you want to add to the channel.
        type_(Text): The membership type of a user, DEFAULT or HIDDEN. Default members are always returned as part of
            ListChannelMemberships. Hidden members are only returned if the type filter in
            ListChannelMemberships equals HIDDEN. Otherwise hidden members are not returned. This is only
            supported by moderators.
        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_membership.present:
                - name: value
                - channel_arn: value
                - member_arn: value
                - type_: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.channel_membership.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_membership(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.create_channel_membership(
                ctx,
                
                
                **{"ChannelArn": channel_arn, "MemberArn": member_arn, "Type": type_, "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_membership(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, channel_arn: Text, member_arn: Text, chime_bearer: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a member from a 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 from which you want to remove the user.
        member_arn(Text): The ARN of the member that you're removing from the channel.
        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_membership.absent:
                - name: value
                - channel_arn: value
                - member_arn: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.channel_membership.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_membership(name)

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

