"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.metadata = void 0;
const db_1 = require("@b/db");
const error_1 = require("@b/utils/error");
const errors_1 = require("@b/utils/schema/errors");
exports.metadata = {
    summary: "Bulk Update FAQs",
    description: "Updates multiple FAQ entries in a single operation. Applies the same update data to all specified FAQ IDs.",
    operationId: "bulkUpdateFaqs",
    tags: ["Admin", "FAQ", "BulkOperations"],
    requiresAuth: true,
    requestBody: {
        required: true,
        content: {
            "application/json": {
                schema: {
                    type: "object",
                    properties: {
                        ids: {
                            type: "array",
                            items: { type: "string", format: "uuid" },
                            description: "Array of FAQ IDs to update",
                        },
                        data: {
                            type: "object",
                            description: "Fields to update on all FAQs",
                        },
                    },
                    required: ["ids", "data"],
                },
            },
        },
    },
    responses: {
        200: (0, errors_1.successMessageResponse)("FAQs updated successfully"),
        400: errors_1.badRequestResponse,
        401: errors_1.unauthorizedResponse,
        500: errors_1.serverErrorResponse,
    },
    permission: "edit.faq",
    logModule: "ADMIN_FAQ",
    logTitle: "Bulk update FAQs",
};
exports.default = async (data) => {
    const { user, body, ctx } = data;
    if (!(user === null || user === void 0 ? void 0 : user.id)) {
        throw (0, error_1.createError)({ statusCode: 401, message: "Unauthorized" });
    }
    const { ids, data: updateData } = body;
    if (!Array.isArray(ids) || ids.length === 0) {
        ctx === null || ctx === void 0 ? void 0 : ctx.fail("No FAQ IDs provided");
        throw (0, error_1.createError)({ statusCode: 400, message: "No FAQ IDs provided" });
    }
    ctx === null || ctx === void 0 ? void 0 : ctx.step("Updating FAQs");
    await db_1.models.faq.update(updateData, { where: { id: ids } });
    ctx === null || ctx === void 0 ? void 0 : ctx.success("FAQs updated successfully");
    return { message: "FAQs updated successfully" };
};
