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

export const blockTools = [
  {
    name: 'acuity_list_blocks',
    description: 'List all calendar blocks (blocked time)',
    inputSchema: {
      type: 'object',
      properties: {
        calendarID: {
          type: 'number',
          description: 'Filter by calendar ID',
        },
      },
    },
    handler: async (args: any, client: AcuityClient) => {
      const blocks = await client.getBlocks(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(blocks, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_block',
    description: 'Get a specific block by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Block ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const block = await client.getBlock(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(block, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_block',
    description: 'Create a new calendar block (block out time)',
    inputSchema: {
      type: 'object',
      properties: {
        calendarID: {
          type: 'number',
          description: 'Calendar ID',
        },
        start: {
          type: 'string',
          description: 'Start datetime in ISO format',
        },
        end: {
          type: 'string',
          description: 'End datetime in ISO format',
        },
        notes: {
          type: 'string',
          description: 'Notes about the block',
        },
      },
      required: ['calendarID', 'start', 'end'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const block = await client.createBlock(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(block, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_block',
    description: 'Update an existing calendar block',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Block ID',
        },
        calendarID: {
          type: 'number',
          description: 'Updated calendar ID',
        },
        start: {
          type: 'string',
          description: 'Updated start datetime',
        },
        end: {
          type: 'string',
          description: 'Updated end datetime',
        },
        notes: {
          type: 'string',
          description: 'Updated notes',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const block = await client.updateBlock(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(block, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_delete_block',
    description: 'Delete a calendar block',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Block ID to delete',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      await client.deleteBlock(args.id);
      return {
        content: [
          {
            type: 'text',
            text: `Block ${args.id} deleted successfully`,
          },
        ],
      };
    },
  },
];
