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

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

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

    acuity_create_client: {
      description: 'Create a new client',
      inputSchema: z.object({
        firstName: z.string().describe('First name'),
        lastName: z.string().describe('Last name'),
        email: z.string().email().describe('Email address'),
        phone: z.string().optional().describe('Phone number'),
        notes: z.string().optional().describe('Client notes')
      }),
      handler: async (args: any) => {
        const clientData = await client.createClient(args);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(clientData, null, 2)
          }]
        };
      }
    },

    acuity_update_client: {
      description: 'Update an existing client',
      inputSchema: z.object({
        id: z.number().describe('Client ID'),
        firstName: z.string().optional(),
        lastName: z.string().optional(),
        email: z.string().email().optional(),
        phone: z.string().optional(),
        notes: z.string().optional()
      }),
      handler: async (args: any) => {
        const { id, ...data } = args;
        const clientData = await client.updateClient(id, data);
        return {
          content: [{
            type: 'text',
            text: JSON.stringify(clientData, null, 2)
          }]
        };
      }
    },

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