import {
  TDependentAnswerPresetOf,
  TDirectAnswerPresetOf,
  TQuestionIdentity,
  TQuestionType,
} from "./types";

/**
 * Declares a Direct Answer: an Answer Preset computed from the current Store's Store Preset.
 * `answer` returns the value to write, or `null` to leave a Skipped Question. Checkbox questions
 * take a list of choices; text and radio questions take a single value.
 */
export function setDirectAnswerPreset<TStorePreset, TType extends TQuestionType>(
  sectionName: TQuestionIdentity["sectionName"],
  questionLabel: TQuestionIdentity["questionLabel"],
  questionType: TType,
  answer: TDirectAnswerPresetOf<TStorePreset, TType>["answer"],
): TDirectAnswerPresetOf<TStorePreset, TType> {
  return {
    sectionName,
    questionLabel,
    questionType,
    answerDependency: "directAnswer",
    answer,
  };
}

/**
 * Declares a Dependent Answer: an Answer Preset computed from the values the Autofill computed for
 * other questions in the same Answer Preset set. `dependencyKeys` are those questions' keys, and
 * `answer` receives their values as strings in the same order. `answer` returns the value to write,
 * or `null` to leave a Skipped Question.
 */
export function setDependentAnswerPreset<TType extends TQuestionType>(
  sectionName: TQuestionIdentity["sectionName"],
  questionLabel: TQuestionIdentity["questionLabel"],
  questionType: TType,
  dependencyKeys: TDependentAnswerPresetOf<TType>["dependencyKeys"],
  answer: TDependentAnswerPresetOf<TType>["answer"],
): TDependentAnswerPresetOf<TType> {
  return {
    sectionName,
    questionLabel,
    questionType,
    answerDependency: "dependentAnswer",
    dependencyKeys,
    answer,
  };
}
