import { z } from 'zod';
import { StripeClient } from '../clients/stripe.js';
import { Event } from '../types/index.js';

export default [
  {
    name: 'stripe_list_events',
    description: 'List all events (webhook events that occurred in the account)',
    inputSchema: z.object({
      limit: z.number().min(1).max(100).optional().describe('Number of events to return (1-100)'),
      starting_after: z.string().optional().describe('Cursor for pagination'),
      ending_before: z.string().optional().describe('Cursor for pagination'),
      created: z.union([
        z.number(),
        z.object({
          gt: z.number().optional(),
          gte: z.number().optional(),
          lt: z.number().optional(),
          lte: z.number().optional(),
        })
      ]).optional().describe('Filter by creation timestamp or range'),
      delivery_success: z.boolean().optional().describe('Filter by successful webhook delivery'),
      type: z.string().optional().describe('Filter by event type (e.g., "charge.succeeded")'),
      types: z.array(z.string()).optional().describe('Filter by multiple event types')
    }),
    handler: async (client: StripeClient, args: any) => {
      return await client.list<Event>('/events', args);
    }
  },
  {
    name: 'stripe_get_event',
    description: 'Retrieve a specific event by ID',
    inputSchema: z.object({
      event_id: z.string().describe('The ID of the event to retrieve'),
      expand: z.array(z.string()).optional().describe('Fields to expand')
    }),
    handler: async (client: StripeClient, args: any) => {
      const { event_id, expand } = args;
      const params = expand ? { expand } : undefined;
      return await client.retrieve<Event>('/events', event_id, params);
    }
  }
];
