# This constants.py used to be shared with the official SDK and the backend.
# This file contains constants and enums used in the ChattedRooms API.


# Visibility enum: 0 is PRIVATE, 1 is PUBLIC, and 2 is UNLISTED
class Visibility:
    """
        Visibility for a character.
        0 = PRIVATE: Only the owner can see the character.
        1 = PUBLIC: Everyone can see the character.
        2 = UNLISTED: Only people with the link (or bot ID) can see the character.
        This is used to determine the visibility of a character in the ChattedRooms API.
    """
    PRIVATE = 0
    PUBLIC = 1
    UNLISTED = 2

# Chat Message
class CRChatMessage:
    """
        A message from ChattedRooms.
        This class is used to represent a message in the ChattedRooms API.
        It contains the message content, role (user or assistant), and ID.
        The role is used to identify the sender of the message.
        The ID is used to identify the message (its a stringified UUID).
        The content is the actual message.
    """
    def __init__(self, message: str, role: str, id:str):
        self.content = message
        self.role = role
        self.id = id
    
    def to_dict(self):
        return {
            "content": self.content,
            "role": self.role,
            "id": self.id
        }

class CRChatShort:
    """
        A short representation of a chat from ChattedRooms.
        This class is used to represent a chat without messages in the ChattedRooms API.
        It contains the chat ID, bot ID, and visibility.
    """
    def __init__(self, id: int, botid: int, visibility: int):
        self.id = id
        self.botid = botid
        self.visibility = visibility

    def to_dict(self):
        return {
            "id": self.id,
            "botid": self.botid,
            "visibility": self.visibility
        }

class CRChat(CRChatShort):
    """
        A chat from ChattedRooms.
        This class is used to represent a chat in the ChattedRooms API.
        It contains the chat ID, bot ID, visibility, and messages.
    """
    def __init__(self, id: int, botid: int, visibility: int, messages: list['CRChatMessage']):
        super().__init__(id, botid, visibility)
        self.messages = messages

    def to_dict(self):
        return {
            "id": self.id,
            "botid": self.botid,
            "visibility": self.visibility,
            "messages": [message.to_dict() for message in self.messages]
        }


class CRCharacter:
    """
        A character from ChattedRooms.
        This class is used to represent a character in the ChattedRooms API.
        It contains the character ID, name, subtitle, and visibility.
    """
    def __init__(self, id: int, name: str, subtitle: str, visibility: int):
        self.id = id
        self.name = name
        self.subtitle = subtitle
        self.visibility = visibility

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "visibility": self.visibility
        }

class CRFullCharacter(CRCharacter):
    """
        A full character from ChattedRooms.
        This class is used to represent a character in the ChattedRooms API with additional information.
        It contains the character ID, name, subtitle, visibility, description, avatar, and tags.
    """
    def __init__(self, id: int, name: str, subtitle: str, visibility: int, description: str, avatar: str, tags: list[str]):
        super().__init__(id, name, subtitle, visibility)
        self.description = description
        self.avatar = avatar
        self.tags = tags

    def to_dict(self):
        return {
            "id": self.id,
            "name": self.name,
            "subtitle": self.subtitle,
            "visibility": self.visibility,
            "description": self.description,
            "avatar": self.avatar,
            "tags": self.tags
        }

class CRBaseUser:
    """
        Base class for a user in the ChattedRooms SDK.
        Contains basic user information: id, name, and avatar.
    """
    def __init__(self, id: str, name: str, avatar: str):
        self.id = id
        self.name = name
        self.avatar = avatar

class CRRemoteUser(CRBaseUser):
    """
        Someone who is registered.
        Represents a user in the ChattedRooms API.
        Contains the user ID, name, avatar, bots, display name, and description.
    """
    def __init__(self, id: str, name: str, avatar: str, bots: list[CRCharacter], display_name: str, description: str):
        super().__init__(id, name, avatar)
        self.bots = bots
        self.display_name = display_name
        self.description = description

class CRLocalUser(CRRemoteUser):
    """
        A local user.
        This class is used to represent the currently logged in user in the ChattedRooms API.
        It contains the user ID, name, avatar, bots, display name, and description.
    """
    def __init__(self, id: str, name: str, avatar: str, bots: list[CRCharacter], display_name: str, description: str):
        super().__init__(id, name, avatar, bots, display_name, description)