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

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

    acuity_create_label: {
      description: 'Create a new label',
      inputSchema: z.object({
        name: z.string().describe('Label name'),
        color: z.string().optional().describe('Label color (hex code)')
      }),
      handler: async (args: any) => {
        const label = await client.createLabel(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(label, null, 2)
          }]
        };
      }
    },

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

    acuity_add_label_to_appointment: {
      description: 'Add a label to an appointment',
      inputSchema: z.object({
        appointmentId: z.number().describe('Appointment ID'),
        labelId: z.number().describe('Label ID')
      }),
      handler: async (args: any) => {
        await client.addLabelToAppointment(args.appointmentId, args.labelId);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({ success: true, message: 'Label added to appointment' })
          }]
        };
      }
    },

    acuity_remove_label_from_appointment: {
      description: 'Remove a label from an appointment',
      inputSchema: z.object({
        appointmentId: z.number().describe('Appointment ID'),
        labelId: z.number().describe('Label ID')
      }),
      handler: async (args: any) => {
        await client.removeLabelFromAppointment(args.appointmentId, args.labelId);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({ success: true, message: 'Label removed from appointment' })
          }]
        };
      }
    }
  };
}
