import { z } from 'zod';
import { AcuityClient } from '../clients/acuity.js';

export function createWebhooksTools(client: AcuityClient) {
  return {
    acuity_list_webhooks: {
      description: 'List all webhooks',
      inputSchema: z.object({}),
      handler: async () => {
        const webhooks = await client.listWebhooks();
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(webhooks, null, 2)
          }]
        };
      }
    },

    acuity_create_webhook: {
      description: 'Create a new webhook',
      inputSchema: z.object({
        event: z.string().describe('Event type (e.g., appointment.scheduled, appointment.canceled)'),
        url: z.string().url().describe('Webhook URL')
      }),
      handler: async (args: any) => {
        const webhook = await client.createWebhook(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(webhook, null, 2)
          }]
        };
      }
    },

    acuity_delete_webhook: {
      description: 'Delete a webhook',
      inputSchema: z.object({
        id: z.number().describe('Webhook ID')
      }),
      handler: async (args: any) => {
        await client.deleteWebhook(args.id);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({ success: true, message: 'Webhook deleted' })
          }]
        };
      }
    }
  };
}
