import { z } from 'zod';
import type { AirtableClient } from '../clients/airtable.js';
import { BaseIdSchema } from '../types/index.js';

/**
 * Bases Tools
 * 
 * Tools for managing Airtable bases (workspaces).
 */

export function getTools(client: AirtableClient) {
  return [
    // ========================================================================
    // List Bases
    // ========================================================================
    {
      name: 'airtable_list_bases',
      description:
        'List all bases (workspaces) the authenticated user has access to. Returns base ID, name, and permission level. Supports pagination via offset.',
      inputSchema: z.object({
        offset: z
          .string()
          .optional()
          .describe('Pagination offset from previous response. Omit for first page.'),
      }),
      execute: async (args: { offset?: string }) => {
        const response = await client.listBases(args.offset);
        return {
          bases: response.bases,
          offset: response.offset,
          hasMore: !!response.offset,
        };
      },
    },

    // ========================================================================
    // Get Base
    // ========================================================================
    {
      name: 'airtable_get_base',
      description:
        'Get details about a specific base including its ID, name, and permission level (none, read, comment, edit, create).',
      inputSchema: z.object({
        baseId: BaseIdSchema.describe('The ID of the base (starts with app).'),
      }),
      execute: async (args: { baseId: string }) => {
        const base = await client.getBase(args.baseId as any);
        return base;
      },
    },
  ];
}
