// Event Types Tools

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

export function createEventTypesTools(client: CalendlyClient) {
  return {
    calendly_list_event_types: {
      description: 'List event types for a user or organization',
      parameters: {
        type: 'object',
        properties: {
          organization: {
            type: 'string',
            description: 'Organization URI to filter by',
          },
          user: {
            type: 'string',
            description: 'User URI to filter by',
          },
          active: {
            type: 'boolean',
            description: 'Filter by active status',
          },
          count: {
            type: 'number',
            description: 'Number of results per page (max 100)',
            default: 20,
          },
          page_token: {
            type: 'string',
            description: 'Pagination token',
          },
          sort: {
            type: 'string',
            description: 'Sort order (e.g., name:asc, name:desc)',
          },
        },
      },
      handler: async (args: any) => {
        const result = await client.listEventTypes(args);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    calendly_get_event_type: {
      description: 'Get details of a specific event type by UUID',
      parameters: {
        type: 'object',
        properties: {
          uuid: {
            type: 'string',
            description: 'Event type UUID',
          },
        },
        required: ['uuid'],
      },
      handler: async (args: any) => {
        const result = await client.getEventType(args.uuid);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    calendly_list_available_times: {
      description: 'List available time slots for an event type within a date range',
      parameters: {
        type: 'object',
        properties: {
          event_type_uri: {
            type: 'string',
            description: 'Event type URI',
          },
          start_time: {
            type: 'string',
            description: 'Start of range (ISO 8601)',
          },
          end_time: {
            type: 'string',
            description: 'End of range (ISO 8601)',
          },
        },
        required: ['event_type_uri', 'start_time', 'end_time'],
      },
      handler: async (args: any) => {
        const result = await client.listAvailableTimes(args.event_type_uri, {
          start_time: args.start_time,
          end_time: args.end_time,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },
  };
}
