import { isNullOrUndefined } from '@coveo/bueno';
import { createSelector } from '@reduxjs/toolkit';
import { selectAnswer, } from '../../api/knowledge/stream-answer-api.js';
import { selectQuery } from '../query/query-selectors.js';
export const generativeQuestionAnsweringIdSelector = (state) => {
    if (isGeneratedAnswerSection(state)) {
        return { answerAPIEnabled: true, id: selectAnswer(state).data?.answerId };
    }
    if (isSearchSection(state)) {
        return {
            answerAPIEnabled: false,
            id: state.search.response.extendedResults.generativeQuestionAnsweringId,
        };
    }
    return { answerAPIEnabled: false, id: undefined };
};
const isSearchSection = (state) => 'search' in state;
const isGeneratedAnswerSection = (state) => 'answer' in state &&
    'generatedAnswer' in state &&
    !isNullOrUndefined(state.generatedAnswer?.answerConfigurationId);
export const selectFieldsToIncludeInCitation = (state) => state.generatedAnswer?.fieldsToIncludeInCitations;
export const citationSourceSelector = createSelector((state) => state.generatedAnswer?.citations, (_state, citationId) => citationId, (citations, citationId) => citations?.find((citation) => citation.id === citationId));
export const selectAnswerTriggerParams = createSelector((state) => selectQuery(state)?.q, (state) => state.search.requestId, (q, requestId) => ({ q, requestId }));
