// Users Tools

import { CalendlyClient } from '../clients/calendly.js';

export function createUsersTools(client: CalendlyClient) {
  return {
    calendly_get_current_user: {
      description: 'Get the currently authenticated user information',
      parameters: {
        type: 'object',
        properties: {},
      },
      handler: async (args: any) => {
        const result = await client.getCurrentUser();
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    calendly_get_user: {
      description: 'Get user information by URI',
      parameters: {
        type: 'object',
        properties: {
          uri: {
            type: 'string',
            description: 'User URI',
          },
        },
        required: ['uri'],
      },
      handler: async (args: any) => {
        const result = await client.getUserByUri(args.uri);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    calendly_list_user_busy_times: {
      description: 'List busy time blocks for a user within a date range',
      parameters: {
        type: 'object',
        properties: {
          user_uri: {
            type: 'string',
            description: 'User URI',
          },
          start_time: {
            type: 'string',
            description: 'Start of range (ISO 8601)',
          },
          end_time: {
            type: 'string',
            description: 'End of range (ISO 8601)',
          },
        },
        required: ['user_uri', 'start_time', 'end_time'],
      },
      handler: async (args: any) => {
        const result = await client.getUserBusyTimes(args.user_uri, {
          start_time: args.start_time,
          end_time: args.end_time,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },
  };
}
