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

hub.exec.boto3.client.chime.create_room_membership
hub.exec.boto3.client.chime.delete_room_membership
hub.exec.boto3.client.chime.list_room_memberships
hub.exec.boto3.client.chime.update_room_membership
"""



from typing import *
import dict_tools.differ as differ
async def present(hub, ctx, name: Text, account_id: Text, room_id: Text, member_id: Text, role: Text = None)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Adds a member to a chat room in an Amazon Chime Enterprise account. A member can be either a user or a bot. The
    member role designates whether the member is a chat room administrator or a general chat room member.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The Amazon Chime account ID.
        room_id(Text): The room ID.
        member_id(Text): The Amazon Chime member ID (user ID or bot ID).
        role(Text, optional): The role of the member. Defaults to None.

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_present:
              aws_auto.chime.room_membership.present:
                - name: value
                - account_id: value
                - room_id: value
                - member_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.room_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.list_room_memberships(name)

    if before:
        result["comment"] = f"'{name}' already exists"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.create_room_membership(
                ctx,
                
                
                **{"AccountId": account_id, "RoomId": room_id, "MemberId": member_id, "Role": role}
            )
            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.list_room_memberships(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

async def absent(hub, ctx, name: Text, account_id: Text, room_id: Text, member_id: Text)  -> Dict[str, Any]:
    r'''
    **Autogenerated function**
    
    Removes a member from a chat room in an Amazon Chime Enterprise account.

    Args:
        name(Text): A name, ID, or JMES search path to identify the resource.
        account_id(Text): The Amazon Chime account ID.
        room_id(Text): The room ID.
        member_id(Text): The member ID (user ID or bot ID).

    Returns:
        Dict[str, Any]

    Examples:

        .. code-block:: sls

            resource_is_absent:
              aws_auto.chime.room_membership.absent:
                - name: value
                - account_id: value
                - room_id: value
                - member_id: value
    '''
    
    result = dict(comment="", changes= None, name=name, result=True)
    ret = await hub.exec.boto3.client.chime.room_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.list_room_memberships(name)

    if not before:
        result["comment"] = f"'{name}' already absent"
    else:
        try:
            ret = await hub.exec.boto3.client.chime.delete_room_membership(
                ctx,
                
                
                **{"AccountId": account_id, "RoomId": room_id, "MemberId": member_id}
            )
            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.list_room_memberships(name)
    result["changes"] = differ.deep_diff(before, after)
    return result

