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

export function createAvailabilityTools(client: AcuityClient) {
  return {
    acuity_get_availability_dates: {
      description: 'Get available dates for an appointment type',
      inputSchema: z.object({
        appointmentTypeID: z.number().describe('Appointment type ID'),
        month: z.string().optional().describe('Month to check (YYYY-MM)'),
        calendarID: z.number().optional().describe('Specific calendar ID'),
        timezone: z.string().optional().describe('Timezone (e.g., America/New_York)')
      }),
      handler: async (args: any) => {
        const dates = await client.getAvailabilityDates(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(dates, null, 2)
          }]
        };
      }
    },

    acuity_get_availability_times: {
      description: 'Get available time slots for a specific date and appointment type',
      inputSchema: z.object({
        appointmentTypeID: z.number().describe('Appointment type ID'),
        date: z.string().describe('Date to check (YYYY-MM-DD)'),
        calendarID: z.number().optional().describe('Specific calendar ID'),
        timezone: z.string().optional().describe('Timezone (e.g., America/New_York)')
      }),
      handler: async (args: any) => {
        const times = await client.getAvailabilityTimes(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(times, null, 2)
          }]
        };
      }
    },

    acuity_get_availability_classes: {
      description: 'Get available class sessions',
      inputSchema: z.object({
        appointmentTypeID: z.number().optional().describe('Filter by appointment type'),
        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 classes = await client.getAvailabilityClasses(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(classes, null, 2)
          }]
        };
      }
    },

    acuity_check_availability: {
      description: 'Check if a specific time slot is available',
      inputSchema: z.object({
        appointmentTypeID: z.number().describe('Appointment type ID'),
        date: z.string().describe('Date (YYYY-MM-DD)'),
        time: z.string().describe('Time (HH:MM)'),
        calendarID: z.number().optional().describe('Calendar ID')
      }),
      handler: async (args: any) => {
        const result = await client.checkAvailability(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(result, null, 2)
          }]
        };
      }
    }
  };
}
