import { z } from 'zod';

// {
//     "language_code": "string",
//     "title": "string",
//     "answer_explanation": "string",
//     "options": [
//       {
//         "id": 0,
//         "text": "string"
//       }
//     ]
// }

export async function questionValidator(optionsLength, submissionObj) {
    const questionObjValidation = z.object({
        language_code: z.string().min(2, "Language code is not set or an unexpected value is received"),
        title: z.string(),
        answer_explanation: z.string(),
        options: z.array(z.object({
            id: z.number(),
            text: z.string(),
        })).length(optionsLength, "Number of options received does not match the original question's option."),
    });

    const validator = await questionObjValidation.safeParse(submissionObj);
    if(!validator.success) {
        throw validator.error
    }
    return validator.data;
}