import { createUeuse } from "@/lib/client";
import ueuseModule from "better-uwuzu-sdk/types/1.6.8/types/modules/ueuse";
import i18next from "i18next";
import { EOL } from "node:os";

const helps = [
  "help",
  "follow",
  "unfollow",
  "weather",
  "miq",
];

export default async function helpCommand(ueuse: ueuseModule, args: string[]) {
  if (args[1] !== undefined) {
    if (!(helps.includes(args[1]))) {
      await createUeuse({
        text: i18next.t("invalidOption", { option: args[1], command: "help" }),
        replyid: ueuse.uniqid,
      }, "無効なオプションである旨");

      return;
    }

    await createUeuse({
      text: i18next.t(`fullHelp${args[1].charAt(0).toUpperCase()}${args[1].slice(1)}`),
      replyid: ueuse.uniqid,
    }, "コマンド詳細");

    return;
  }

  let summarys = "";

  for (let i = 0; i < helps.length; i++) {
    const help = helps[i];
    if (!help)
      continue;

    summarys += `${i18next.t(`help${help.charAt(0).toUpperCase()}${help.slice(1)}`)}${EOL}`;
  }

  await createUeuse({
    text: summarys.trim(),
    replyid: ueuse.uniqid,
  }, "コマンド概要");
}
