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

export const appointmentTools = [
  {
    name: 'acuity_list_appointments',
    description: 'List all appointments with optional pagination and date filters',
    inputSchema: {
      type: 'object',
      properties: {
        max: {
          type: 'number',
          description: 'Maximum number of appointments to return (default 50)',
        },
        offset: {
          type: 'number',
          description: 'Offset for pagination',
        },
        minDate: {
          type: 'string',
          description: 'Minimum date filter (YYYY-MM-DD)',
        },
        maxDate: {
          type: 'string',
          description: 'Maximum date filter (YYYY-MM-DD)',
        },
      },
    },
    handler: async (args: any, client: AcuityClient) => {
      const appointments = await client.getAppointments(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointments, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_get_appointment',
    description: 'Get a specific appointment by ID',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Appointment ID',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const appointment = await client.getAppointment(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointment, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_create_appointment',
    description: 'Create a new appointment',
    inputSchema: {
      type: 'object',
      properties: {
        appointmentTypeID: {
          type: 'number',
          description: 'ID of the appointment type',
        },
        datetime: {
          type: 'string',
          description: 'Appointment datetime in ISO format',
        },
        firstName: {
          type: 'string',
          description: 'Client first name',
        },
        lastName: {
          type: 'string',
          description: 'Client last name',
        },
        email: {
          type: 'string',
          description: 'Client email address',
        },
        phone: {
          type: 'string',
          description: 'Client phone number',
        },
        calendarID: {
          type: 'number',
          description: 'Calendar ID',
        },
        timezone: {
          type: 'string',
          description: 'Timezone (e.g., America/New_York)',
        },
        notes: {
          type: 'string',
          description: 'Appointment notes',
        },
        certificate: {
          type: 'string',
          description: 'Certificate code to apply',
        },
      },
      required: ['appointmentTypeID', 'datetime', 'firstName', 'lastName', 'email'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const appointment = await client.createAppointment(args);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointment, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_update_appointment',
    description: 'Update an existing appointment',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Appointment ID',
        },
        datetime: {
          type: 'string',
          description: 'New appointment datetime in ISO format',
        },
        firstName: {
          type: 'string',
          description: 'Updated first name',
        },
        lastName: {
          type: 'string',
          description: 'Updated last name',
        },
        email: {
          type: 'string',
          description: 'Updated email',
        },
        phone: {
          type: 'string',
          description: 'Updated phone',
        },
        notes: {
          type: 'string',
          description: 'Updated notes',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const { id, ...updateParams } = args;
      const appointment = await client.updateAppointment(id, updateParams);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointment, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_cancel_appointment',
    description: 'Cancel an appointment',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Appointment ID to cancel',
        },
      },
      required: ['id'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const appointment = await client.cancelAppointment(args.id);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointment, null, 2),
          },
        ],
      };
    },
  },
  {
    name: 'acuity_reschedule_appointment',
    description: 'Reschedule an appointment to a new datetime',
    inputSchema: {
      type: 'object',
      properties: {
        id: {
          type: 'number',
          description: 'Appointment ID to reschedule',
        },
        datetime: {
          type: 'string',
          description: 'New datetime in ISO format',
        },
      },
      required: ['id', 'datetime'],
    },
    handler: async (args: any, client: AcuityClient) => {
      const appointment = await client.rescheduleAppointment(args.id, args.datetime);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(appointment, null, 2),
          },
        ],
      };
    },
  },
];
