import { prismaClient } from '../database/prismaClient.js';
export async function createMessage(data) {
    console.log(`Creating message ${data.messageId} for chat: ${data.chat.connect?.id}`);
    return prismaClient.message.create({
        data,
    });
}
export async function getMessage(chatId, messageId) {
    console.log(`Getting message ${messageId} from chat ${chatId}`);
    return prismaClient.message.findUnique({
        where: {
            chatId_messageId: {
                chatId: chatId,
                messageId: messageId,
            },
        },
    });
}
export async function getMessagesByChatId(chatId) {
    console.log(`Getting all messages for chat ${chatId}`);
    return prismaClient.message.findMany({
        where: { chatId: chatId },
    });
}
export async function getMessageCountByChatId(chatId) {
    console.log(`Getting message count for chat ${chatId}`);
    return prismaClient.message.count({
        where: { chatId: chatId },
    });
}
export async function listMessages() {
    console.log('Listing all messages');
    return prismaClient.message.findMany();
}
export async function updateMessage(chatId, messageId, data) {
    console.log(`Updating message ${messageId} in chat ${chatId}`);
    return prismaClient.message.update({
        where: {
            chatId_messageId: {
                chatId: chatId,
                messageId: messageId,
            },
        },
        data,
    });
}
export async function deleteMessage(chatId, messageId) {
    console.log(`Deleting message ${messageId} from chat ${chatId}`);
    return prismaClient.message.delete({
        where: {
            chatId_messageId: {
                chatId: chatId,
                messageId: messageId,
            },
        },
    });
}
