import { ArrayValue, BooleanValue, NumberValue, RecordValue, StringValue, } from '@coveo/bueno';
import { createAction } from '@reduxjs/toolkit';
import { requiredNonEmptyString, validatePayload, } from '../../utils/validate-payload.js';
import { answerContentFormatSchema, citationSchema, } from '../generated-answer/generated-answer-actions.js';
import { GENERATION_STEP_NAMES, } from '../generated-answer/generated-answer-state.js';
const stringValue = new StringValue({ required: true });
export const setIsEnabled = createAction('followUpAnswers/setIsEnabled', (payload) => validatePayload(payload, new BooleanValue({ required: true })));
export const setFollowUpAnswersConversationId = createAction('followUpAnswers/setFollowUpAnswersConversationId', (payload) => validatePayload(payload, requiredNonEmptyString));
export const createFollowUpAnswer = createAction('followUpAnswers/createFollowUpAnswer', (payload) => validatePayload(payload, {
    question: requiredNonEmptyString,
}));
export const setActiveFollowUpAnswerId = createAction('followUpAnswers/setActiveFollowUpAnswerId', (payload) => validatePayload(payload, requiredNonEmptyString));
export const setFollowUpAnswerContentFormat = createAction('followUpAnswers/setFollowUpAnswerContentFormat', (payload) => validatePayload(payload, {
    contentFormat: answerContentFormatSchema,
    answerId: requiredNonEmptyString,
}));
export const setFollowUpIsLoading = createAction('followUpAnswers/setFollowUpIsLoading', (payload) => validatePayload(payload, {
    isLoading: new BooleanValue({ required: true }),
    answerId: requiredNonEmptyString,
}));
export const setFollowUpIsStreaming = createAction('followUpAnswers/setFollowUpIsStreaming', (payload) => validatePayload(payload, {
    isStreaming: new BooleanValue({ required: true }),
    answerId: requiredNonEmptyString,
}));
export const followUpMessageChunkReceived = createAction('followUpAnswers/followUpMessageChunkReceived', (payload) => validatePayload(payload, {
    textDelta: stringValue,
    answerId: requiredNonEmptyString,
}));
export const followUpCitationsReceived = createAction('followUpAnswers/followUpCitationsReceived', (payload) => validatePayload(payload, {
    citations: new ArrayValue({
        required: true,
        each: new RecordValue({
            values: citationSchema,
        }),
    }),
    answerId: requiredNonEmptyString,
}));
export const followUpCompleted = createAction('followUpAnswers/followUpCompleted', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
    cannotAnswer: new BooleanValue({ required: false }),
}));
export const followUpFailed = createAction('followUpAnswers/followUpFailed', (payload) => validatePayload(payload, {
    message: new StringValue(),
    code: new NumberValue({ min: 0 }),
    answerId: requiredNonEmptyString,
}));
export const activeFollowUpStartFailed = createAction('followUpAnswers/activeFollowUpStartFailed', (payload) => validatePayload(payload, {
    message: new StringValue(),
}));
export const likeFollowUp = createAction('followUpAnswers/likeFollowUp', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
}));
export const dislikeFollowUp = createAction('followUpAnswers/dislikeFollowUp', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
}));
export const submitFollowUpFeedback = createAction('followUpAnswers/submitFollowUpFeedback', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
}));
export const resetFollowUpAnswers = createAction('followUpAnswers/resetFollowUpAnswers');
export const followUpStepStarted = createAction('followUpAnswers/stepStarted', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
    name: new StringValue({
        required: true,
        constrainTo: GENERATION_STEP_NAMES,
    }),
    startedAt: new NumberValue({ min: 0, required: true }),
}));
export const followUpStepFinished = createAction('followUpAnswers/stepFinished', (payload) => validatePayload(payload, {
    answerId: requiredNonEmptyString,
    name: new StringValue({
        required: true,
        constrainTo: GENERATION_STEP_NAMES,
    }),
    finishedAt: new NumberValue({ min: 0, required: true }),
}));
