// Scheduling Tools

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

export function createSchedulingTools(client: CalendlyClient) {
  return {
    calendly_create_scheduling_link: {
      description: 'Create a single-use scheduling link for an event type or group',
      parameters: {
        type: 'object',
        properties: {
          owner: {
            type: 'string',
            description: 'Owner URI (event type or group)',
          },
          owner_type: {
            type: 'string',
            enum: ['EventType', 'Group'],
            description: 'Type of owner',
          },
          max_event_count: {
            type: 'number',
            description: 'Maximum number of events that can be scheduled (1-1000)',
            default: 1,
          },
        },
        required: ['owner', 'owner_type'],
      },
      handler: async (args: any) => {
        const result = await client.createSchedulingLink({
          owner: args.owner,
          owner_type: args.owner_type,
          max_event_count: args.max_event_count || 1,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

    calendly_list_routing_forms: {
      description: 'List routing forms for an organization',
      parameters: {
        type: 'object',
        properties: {
          organization_uri: {
            type: 'string',
            description: 'Organization URI',
          },
          count: {
            type: 'number',
            description: 'Number of results per page',
            default: 20,
          },
          page_token: {
            type: 'string',
            description: 'Pagination token',
          },
          sort: {
            type: 'string',
            description: 'Sort order',
          },
        },
        required: ['organization_uri'],
      },
      handler: async (args: any) => {
        const result = await client.listRoutingForms(args.organization_uri, {
          count: args.count,
          page_token: args.page_token,
          sort: args.sort,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      },
    },

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