import type { PlimiPlugin, UnknownPlimiPlugin } from "./plugin-types";
import { base64Plugin } from "../../tools/base64";
import { imageOptimizerPlugin } from "../../tools/image-optimizer";
import { imageEditorPlugin } from "../../tools/image-editor";
import { pdfMergerPlugin } from "../../tools/pdf-merger";
import { hashGeneratorPlugin } from "../../tools/hash-generator";
import { uuidGeneratorPlugin } from "../../tools/uuid-generator";
import { jsonFormatterPlugin } from "../../tools/json-formatter";
import { textCasePlugin } from "../../tools/text-case";
import { urlEncoderPlugin } from "../../tools/url-encoder";
import { loremIpsumPlugin } from "../../tools/lorem-ipsum";
import { colorConverterPlugin } from "../../tools/color-converter";
import { regexTesterPlugin } from "../../tools/regex-tester";
import { numberBasePlugin } from "../../tools/number-base";
import { timestampConverterPlugin } from "../../tools/timestamp-converter";
import { markdownToHtmlPlugin } from "../../tools/markdown-to-html";
import { textDiffPlugin } from "../../tools/text-diff";
import { htmlEntityPlugin } from "../../tools/html-entity";
import { variablesConverterPlugin } from "../../tools/variables-converter";
import { pdfSplitterPlugin } from "../../tools/pdf-splitter";
import { pdfWatermarkPlugin } from "../../tools/pdf-watermark";
import { imageRedactorPlugin } from "../../tools/image-redactor";
import { exifScrubberPlugin } from "../../tools/exif-scrubber";
import { jwtDecoderPlugin } from "../../tools/jwt-decoder";
import { csvToolsPlugin } from "../../tools/csv-tools";
import { qrCodeGeneratorPlugin } from "../../tools/qr-code-generator";
import { passwordGeneratorPlugin } from "../../tools/password-generator";
import { fileChecksumVerifierPlugin } from "../../tools/file-checksum-verifier";
import { svgViewerPlugin } from "../../tools/svg-viewer";
import { backgroundRemoverPlugin } from "../../tools/background-remover";

function erasePlugin<TOptions>(plugin: PlimiPlugin<TOptions>): UnknownPlimiPlugin {
  return plugin as unknown as UnknownPlimiPlugin;
}

export const pluginRegistry: UnknownPlimiPlugin[] = [
  erasePlugin(base64Plugin),
  erasePlugin(hashGeneratorPlugin),
  erasePlugin(uuidGeneratorPlugin),
  erasePlugin(jsonFormatterPlugin),
  erasePlugin(textCasePlugin),
  erasePlugin(urlEncoderPlugin),
  erasePlugin(loremIpsumPlugin),
  erasePlugin(colorConverterPlugin),
  erasePlugin(regexTesterPlugin),
  erasePlugin(numberBasePlugin),
  erasePlugin(timestampConverterPlugin),
  erasePlugin(variablesConverterPlugin),
  erasePlugin(markdownToHtmlPlugin),
  erasePlugin(textDiffPlugin),
  erasePlugin(htmlEntityPlugin),
  erasePlugin(imageEditorPlugin),
  erasePlugin(imageOptimizerPlugin),
  erasePlugin(pdfMergerPlugin),
  erasePlugin(pdfSplitterPlugin),
  erasePlugin(pdfWatermarkPlugin),
  erasePlugin(imageRedactorPlugin),
  erasePlugin(exifScrubberPlugin),
  erasePlugin(jwtDecoderPlugin),
  erasePlugin(csvToolsPlugin),
  erasePlugin(qrCodeGeneratorPlugin),
  erasePlugin(passwordGeneratorPlugin),
  erasePlugin(fileChecksumVerifierPlugin),
  erasePlugin(svgViewerPlugin),
  erasePlugin(backgroundRemoverPlugin),
];

export function getAllPlugins(): UnknownPlimiPlugin[] {
  return pluginRegistry;
}

export function getPluginById(id: string): UnknownPlimiPlugin | undefined {
  return pluginRegistry.find((plugin) => plugin.manifest.id === id);
}

export function getPluginsByCategory(category: string): UnknownPlimiPlugin[] {
  return pluginRegistry.filter(
    (plugin) => plugin.manifest.category === category
  );
}
