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

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

    acuity_get_calendar: {
      description: 'Get a specific calendar by ID',
      inputSchema: z.object({
        id: z.number().describe('Calendar ID')
      }),
      handler: async (args: any) => {
        const calendar = await client.getCalendar(args.id);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(calendar, null, 2)
          }]
        };
      }
    },

    acuity_create_calendar: {
      description: 'Create a new calendar',
      inputSchema: z.object({
        name: z.string().describe('Calendar name'),
        email: z.string().email().optional().describe('Calendar email'),
        location: z.string().optional().describe('Location'),
        timezone: z.string().optional().describe('Timezone (e.g., America/New_York)')
      }),
      handler: async (args: any) => {
        const calendar = await client.createCalendar(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(calendar, null, 2)
          }]
        };
      }
    },

    acuity_update_calendar: {
      description: 'Update an existing calendar',
      inputSchema: z.object({
        id: z.number().describe('Calendar ID'),
        name: z.string().optional(),
        email: z.string().email().optional(),
        location: z.string().optional(),
        timezone: z.string().optional()
      }),
      handler: async (args: any) => {
        const { id, ...data } = args;
        const calendar = await client.updateCalendar(id, data);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(calendar, null, 2)
          }]
        };
      }
    }
  };
}
