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

export function createBlocksTools(client: AcuityClient) {
  return {
    acuity_list_blocks: {
      description: 'List time blocks (blocked time slots)',
      inputSchema: z.object({
        calendarID: z.number().optional().describe('Filter by calendar ID'),
        minDate: z.string().optional().describe('Minimum date (YYYY-MM-DD)'),
        maxDate: z.string().optional().describe('Maximum date (YYYY-MM-DD)')
      }),
      handler: async (args: any) => {
        const blocks = await client.listBlocks(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(blocks, null, 2)
          }]
        };
      }
    },

    acuity_create_block: {
      description: 'Create a new time block to block off time',
      inputSchema: z.object({
        calendarID: z.number().describe('Calendar ID'),
        start: z.string().describe('Start datetime (ISO 8601)'),
        end: z.string().describe('End datetime (ISO 8601)'),
        notes: z.string().optional().describe('Block notes/reason')
      }),
      handler: async (args: any) => {
        const block = await client.createBlock(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(block, null, 2)
          }]
        };
      }
    },

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