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

export interface PasswordGeneratorOptions {
  mode: "password" | "passphrase";
  length: number;
  uppercase: boolean;
  lowercase: boolean;
  numbers: boolean;
  symbols: boolean;
  excludeAmbiguous: boolean;
  count: number;
}

export const passwordGeneratorPlugin: PlimiPlugin<PasswordGeneratorOptions> = {
  manifest: {
    id: "password-generator",
    name: "Password & Passphrase Generator",
    description: "Generate highly secure, random passwords or word-based passphrases locally in your browser.",
    category: "crypto",
    version: "1.0.0",
    tags: ["password", "passphrase", "security", "generator", "random"],
    input: { type: "none" },
    output: { type: "table" },
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "select",
        key: "mode",
        label: "Mode",
        defaultValue: "password",
        options: [
          { label: "Random Password", value: "password" },
          { label: "Word Passphrase", value: "passphrase" },
        ],
      },
      {
        type: "slider",
        key: "length",
        label: "Password Length / Word Count",
        defaultValue: 16,
        min: 6,
        max: 64,
        step: 1,
      },
      {
        type: "boolean",
        key: "uppercase",
        label: "Include Uppercase Letters (A-Z)",
        defaultValue: true,
      },
      {
        type: "boolean",
        key: "lowercase",
        label: "Include Lowercase Letters (a-z)",
        defaultValue: true,
      },
      {
        type: "boolean",
        key: "numbers",
        label: "Include Numbers (0-9)",
        defaultValue: true,
      },
      {
        type: "boolean",
        key: "symbols",
        label: "Include Symbols (!@#$%^&*)",
        defaultValue: true,
      },
      {
        type: "boolean",
        key: "excludeAmbiguous",
        label: "Exclude Ambiguous Characters (e.g. l, 1, I, o, 0, O)",
        defaultValue: false,
      },
      {
        type: "slider",
        key: "count",
        label: "Quantity to Generate",
        defaultValue: 5,
        min: 1,
        max: 20,
        step: 1,
      },
    ],
  },

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

  run: runPasswordGenerator,
};
