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

/**
 * Views Tools
 * 
 * Tools for managing views in Airtable tables.
 * Views are different ways to visualize and filter table data.
 */

export function getTools(client: AirtableClient) {
  return [
    // ========================================================================
    // List Views
    // ========================================================================
    {
      name: 'airtable_list_views',
      description:
        'List all views in a table. Returns view ID, name, and type (grid, form, calendar, gallery, kanban, timeline, gantt).',
      inputSchema: z.object({
        baseId: BaseIdSchema.describe('The ID of the base (starts with app).'),
        tableId: TableIdSchema.describe('The ID of the table (starts with tbl).'),
      }),
      execute: async (args: { baseId: string; tableId: string }) => {
        const views = await client.listViews(args.baseId as any, args.tableId as any);
        return {
          views: views.map((v) => ({
            id: v.id,
            name: v.name,
            type: v.type,
          })),
          count: views.length,
        };
      },
    },

    // ========================================================================
    // Get View
    // ========================================================================
    {
      name: 'airtable_get_view',
      description:
        'Get details about a specific view including its ID, name, and type.',
      inputSchema: z.object({
        baseId: BaseIdSchema.describe('The ID of the base (starts with app).'),
        tableId: TableIdSchema.describe('The ID of the table (starts with tbl).'),
        viewId: ViewIdSchema.describe('The ID of the view (starts with viw).'),
      }),
      execute: async (args: { baseId: string; tableId: string; viewId: string }) => {
        const view = await client.getView(
          args.baseId as any,
          args.tableId as any,
          args.viewId as any
        );
        return view;
      },
    },
  ];
}
