import { describe, expect, it } from "vitest";
import {
  LisioParameterFactory,
  LisioParameterNames,
  LisioBooleanParameterNames,
  LisioNumericParameterNames,
  LisioStringParameterNames,
  CursorSizeOptions,
  DatltonismOptions,
  TranslatorTranslationOptions,
  FontFamilyOptions,
  GoogleTranslationOptions,
  TextAlignOptions,
  ThemeOptions,
} from "../../src/index.js";
import { expectParameterCharacteristics } from "../helpers/parameter-assertions.js";

const factory = LisioParameterFactory.current;

/**
 * A value accepted for each string parameter, respecting its options enum
 * when one exists.
 */
const stringValueByParameterName: Record<LisioStringParameterNames, string> =
  {
    [LisioStringParameterNames.THEME]: ThemeOptions.C_BK_BG_G,
    [LisioStringParameterNames.DALTONISM]: DatltonismOptions.PROTANOPIA,
    [LisioStringParameterNames.FONT_FAMILY]: FontFamilyOptions.ARIAL,
    [LisioStringParameterNames.TEXT_ALIGN]: TextAlignOptions.CENTER,
    [LisioStringParameterNames.CURSOR_SIZE]: CursorSizeOptions.BIG,
    [LisioStringParameterNames.GOOGLE_TRANSLATION]: GoogleTranslationOptions.FR,
    [LisioStringParameterNames.TRANSLATOR_TRANSLATION]: TranslatorTranslationOptions.FR,
    [LisioStringParameterNames.SPEECH_SYNTHESIS_VOICE]: "Google UK English Female",
    [LisioStringParameterNames.UNDERLINE_RED]: "a",
    [LisioStringParameterNames.UNDERLINE_GREEN]: "ab",
    [LisioStringParameterNames.UNDERLINE_BLUE]: "a e",
  };

describe("LisioParameterFactory.buildLisioBooleanParameter (via buildLisioParameter)", () => {
  it.each(Object.values(LisioBooleanParameterNames))(
    "builds the %s boolean parameter with all expected characteristics",
    name => {
      const parameter = factory.buildLisioParameter(name, true);
      expectParameterCharacteristics(parameter, name, true);
    },
  );
});

describe("LisioParameterFactory.buildLisioNumberParameter (via buildLisioParameter)", () => {
  it.each(Object.values(LisioNumericParameterNames))(
    "builds the %s numeric parameter with all expected characteristics",
    name => {
      const parameter = factory.buildLisioParameter(name, 7);
      expectParameterCharacteristics(parameter, name, 7);
    },
  );
});

describe("LisioParameterFactory.buildLisioStringParameter (via buildLisioParameter)", () => {
  it.each(Object.values(LisioStringParameterNames))(
    "builds the %s string parameter with all expected characteristics",
    name => {
      const value = stringValueByParameterName[name];
      const parameter = factory.buildLisioParameter(name, value);
      expectParameterCharacteristics(parameter, name, value);
    },
  );
});

describe("LisioParameterFactory.buildLisioParameter errors", () => {
  it("throws when the value type does not match the parameter type", () => {
    expect(() =>
      factory.buildLisioParameter(
        LisioBooleanParameterNames.VOCA,
        "true" as unknown as boolean,
      ),
    ).toThrow(/LisioProfil_1/);
  });

  it("throws when the parameter name does not exist", () => {
    expect(() =>
      factory.buildLisioParameter(
        "unknown_parameter" as LisioParameterNames,
        true,
      ),
    ).toThrow(/LisioProfil_1/);
  });

  it("throws when a string parameter value is not one of its options", () => {
    expect(() =>
      factory.buildLisioParameter(
        LisioStringParameterNames.THEME,
        "not_a_theme",
      ),
    ).toThrow(/LisioProfil_2/);
  });
});
