import type { IntegrationManifest } from "../manifest/schema.js";

export const googleWorkspaceManifest: IntegrationManifest = {
  id: "google-workspace",
  version: "1.0.0",
  name: "Google Workspace",
  description: "Send Gmail messages, list Drive files, post to Calendar.",
  category: "documents",
  vendor: "Google",
  source: "builtin",
  homepage: "https://workspace.google.com",
  docsUrl: "https://developers.google.com/workspace",
  icon: "Google",
  tags: ["gmail", "drive", "calendar", "oauth"],
  connection: {
    baseUrl: "https://www.googleapis.com",
    allowedHosts: ["www.googleapis.com", "gmail.googleapis.com", "oauth2.googleapis.com", "accounts.google.com"],
    auth: {
      type: "oauth2",
      flow: "authorization_code",
      authUrl: "https://accounts.google.com/o/oauth2/v2/auth",
      tokenUrl: "https://oauth2.googleapis.com/token",
      scopes: [
        "https://www.googleapis.com/auth/gmail.send",
        "https://www.googleapis.com/auth/drive.readonly",
        "https://www.googleapis.com/auth/calendar",
      ],
      scopeSeparator: " ",
      tokenPlacement: "header",
      tokenParamName: "Authorization",
      tokenPrefix: "Bearer ",
      pkce: true,
      extraAuthParams: { access_type: "offline", prompt: "consent" },
      extraTokenParams: {},
      tokenRequestStyle: "form",
    },
    fields: [],
    test: { method: "GET", path: "/oauth2/v3/userinfo", expectStatus: [200], headers: {} },
  },
  capabilities: {
    actions: [
      {
        id: "list_drive_files",
        name: "List Drive files",
        description: "List files visible to the connected Google account.",
        input: [{ name: "q", type: "string", description: "Drive search query", required: false }],
        output: { select: "$.files" },
        request: {
          method: "GET",
          path: "/drive/v3/files",
          query: { q: "{{input.q}}", pageSize: "50", fields: "files(id,name,mimeType,modifiedTime,webViewLink)" },
          headers: {},
          body: undefined,
          bodyEncoding: "none",
          timeoutMs: 30_000,
          retry: { maxAttempts: 3, initialDelayMs: 500, backoff: "exponential", retryOnStatus: [408, 429, 500, 502, 503, 504] },
        },
        mutates: false,
        requiresConfirmation: false,
        tags: ["drive", "read"],
      },
    ],
    triggers: [],
    syncs: [],
  },
  ui: { sections: [] },
};
