"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatController = void 0;
const chatService_js_1 = require("../services/chatService.js");
class ChatController {
    static async getChatRooms(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const result = await chatService_js_1.ChatService.getChatRooms(req.user.userId);
        res.status(result.success ? 200 : 500).json(result);
    }
    static async createChatRoom(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const data = req.body;
        const result = await chatService_js_1.ChatService.createChatRoom(req.user.userId, data);
        res.status(result.success ? 201 : 500).json(result);
    }
    static async getMessages(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const query = {
            roomId: req.params.roomId,
            page: req.query.page,
            limit: req.query.limit,
        };
        const result = await chatService_js_1.ChatService.getMessages(query);
        res.status(result.success ? 200 : 500).json(result);
    }
    static async updateChatRoom(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const roomId = req.params.roomId;
        const data = req.body;
        const result = await chatService_js_1.ChatService.updateChatRoom(req.user.userId, roomId, data);
        res.status(result.success ? 200 : result.status || 400).json(result);
    }
    static async deleteChatRoom(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const roomId = req.params.roomId;
        const result = await chatService_js_1.ChatService.deleteChatRoom(req.user.userId, roomId);
        res.status(result.success ? 200 : result.status || 500).json(result);
    }
    static async addChatRoomMember(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const roomId = req.params.roomId;
        const data = req.body;
        const result = await chatService_js_1.ChatService.addChatRoomMember(req.user.userId, roomId, data);
        res.status(result.success ? 200 : result.status || 500).json(result);
    }
    static async removeChatRoomMember(req, res) {
        if (!req.user) {
            res.status(401).json({ success: false, error: "Unauthorized" });
            return;
        }
        const roomId = req.params.roomId;
        const data = req.body;
        const result = await chatService_js_1.ChatService.removeChatRoomMember(req.user.userId, roomId, data);
        res.status(result.success ? 200 : result.status || 500).json(result);
    }
}
exports.ChatController = ChatController;
