const hookNames = [
  "mail.compose.toolbar",
  "mail.compose.attachments",
  "mail.sidebar.apps",
  "admin.settings.panels",
  "auth.post_login",
  "message.pre_send",
] as const;

export const pluginManifestSchema = {
  type: "object",
  required: ["id", "name", "version"],
  additionalProperties: true,
  properties: {
    id: { type: "string", minLength: 1 },
    name: { type: "string", minLength: 1 },
    version: { type: "string", minLength: 1 },
    description: { type: "string" },
    enabledByDefault: { type: "boolean" },
    permissions: { type: "array", items: { type: "string" } },
    hooks: { type: "array", items: { enum: [...hookNames] } },
    entrypoints: {
      type: "object",
      additionalProperties: false,
      properties: {
        menu: { type: "string" },
        api: { type: "string" },
        ui: { type: "string" },
      },
    },
    contributions: {
      type: "object",
      additionalProperties: false,
      properties: Object.fromEntries(
        hookNames.map((hook) => [
          hook,
          {
            type: "array",
            items: {
              type: "object",
              required: ["hook", "type", "id", "label"],
              additionalProperties: true,
              properties: {
                hook: { const: hook },
                type: { enum: ["button", "panel", "modal", "script"] },
                id: { type: "string", minLength: 1 },
                label: { type: "string", minLength: 1 },
                icon: { type: "string" },
                description: { type: "string" },
                order: { type: "number" },
                mount: { type: "string" },
                css: { type: "string" },
                permissions: { type: "array", items: { type: "string" } },
              },
            },
          },
        ]),
      ),
    },
  },
} as const;
