import type { PlimiPlugin } from "../../core/plugins/plugin-types";
import { runFileChecksumVerifier } from "./run";

export interface FileChecksumVerifierOptions {
  algorithm: "SHA-256" | "SHA-512";
}

export const fileChecksumVerifierPlugin: PlimiPlugin<FileChecksumVerifierOptions> = {
  manifest: {
    id: "file-checksum-verifier",
    name: "File Checksum Verifier",
    description: "Calculate cryptographic SHA-256 or SHA-512 checksums of local files entirely offline in the browser.",
    category: "crypto",
    version: "1.0.0",
    tags: ["checksum", "verifier", "hash", "sha256", "sha512", "file"],
    input: {
      type: "group",
      fields: [
        {
          type: "files",
          key: "files",
          label: "Select File(s)",
          multiple: true,
          description: "Select one or more files to calculate checksums for.",
        },
        {
          type: "text",
          key: "expectedChecksum",
          label: "Expected Checksum (Optional)",
          placeholder: "Paste expected hash to compare against...",
          description: "Case-insensitive. Will be compared against computed hashes.",
        },
      ],
    },
    output: { type: "table" },
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "select",
        key: "algorithm",
        label: "Hash Algorithm",
        defaultValue: "SHA-256",
        options: [
          { label: "SHA-256", value: "SHA-256" },
          { label: "SHA-512", value: "SHA-512" },
        ],
      },
    ],
  },

  capabilities: {
    cancelable: false,
    worker: false,
  },

  run: runFileChecksumVerifier,
};
