"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeChatRoomMemberSchema = exports.addChatRoomMemberSchema = exports.updateChatRoomSchema = exports.updateUserSchema = exports.createChatRoomSchema = exports.registerSchema = exports.loginSchema = exports.validate = void 0;
const zod_1 = require("zod");
const validate = (schema) => {
    return (req, res, next) => {
        try {
            schema.parse(req.body);
            next();
        }
        catch (error) {
            if (error instanceof zod_1.z.ZodError) {
                res.status(400).json({
                    success: false,
                    error: "Validation failed",
                    details: error.errors,
                });
                return;
            }
            next(error);
        }
    };
};
exports.validate = validate;
exports.loginSchema = zod_1.z.object({
    email: zod_1.z.string().email("Invalid email format"),
    password: zod_1.z.string().min(6, "Password must be at least 6 characters long"),
});
exports.registerSchema = zod_1.z.object({
    username: zod_1.z.string().min(3, "Username must be at least 3 characters long"),
    email: zod_1.z.string().email("Invalid email format"),
    password: zod_1.z.string().min(6, "Password must be at least 6 characters long"),
});
exports.createChatRoomSchema = zod_1.z.object({
    name: zod_1.z.string().min(1, "Room name is required"),
    description: zod_1.z.string().optional(),
    memberUsernames: zod_1.z.array(zod_1.z.string()).default([]),
});
exports.updateUserSchema = zod_1.z.object({
    username: zod_1.z.string().min(3, "Username must be at least 3 characters long").optional(),
    email: zod_1.z.string().email("Invalid email format").optional(),
    password: zod_1.z.string().min(6, "Password must be at least 6 characters long").optional(),
    avatar: zod_1.z.string().nullable().optional(),
});
exports.updateChatRoomSchema = zod_1.z.object({
    name: zod_1.z.string().min(1, "Room name is required"),
    description: zod_1.z.string().optional(),
});
exports.addChatRoomMemberSchema = zod_1.z.object({
    username: zod_1.z.string().min(1, "Username is required"),
});
exports.removeChatRoomMemberSchema = zod_1.z.object({
    userId: zod_1.z.string().min(1, "User ID is required"),
});
