import { smokeTest } from './smoke-test.ts'
import { accounts } from './accounts.ts'
import { request } from './request.ts'
import { getUser } from './get-user.ts'
import { listEventTypes } from './list-event-types.ts'
import { getEventType } from './get-event-type.ts'
import { getAvailableTimes } from './get-available-times.ts'
import { listScheduledEvents } from './list-scheduled-events.ts'
import { getScheduledEvent } from './get-scheduled-event.ts'
import { cancelScheduledEvent } from './cancel-scheduled-event.ts'
import { listInvitees } from './list-invitees.ts'
import { getInvitee } from './get-invitee.ts'
import { createInvitee } from './create-invitee.ts'
import { markNoShow } from './mark-no-show.ts'
import { requireRecord } from './types.ts'
const actions = {
'smoke-test': smokeTest,
smoke: smokeTest,
accounts,
request,
'get-user': getUser,
user: getUser,
'list-event-types': listEventTypes,
'event-types': listEventTypes,
'get-event-type': getEventType,
'get-available-times': getAvailableTimes,
'available-times': getAvailableTimes,
'list-scheduled-events': listScheduledEvents,
'scheduled-events': listScheduledEvents,
'get-scheduled-event': getScheduledEvent,
'cancel-scheduled-event': cancelScheduledEvent,
'list-invitees': listInvitees,
invitees: listInvitees,
'get-invitee': getInvitee,
'create-invitee': createInvitee,
'mark-no-show': markNoShow,
} as const
type CalendlyAction = keyof typeof actions
/**
* Dispatch Calendly helper actions. Defaults to `smoke-test`.
* @example
* import calendly from 'kody:@kody/calendly'
* const result = await calendly()
* // => { ok: true, live: false, setup: { connectUrl, patUrl, ... } }
*/
export default async function calendly(
input: { action?: string } & Record<string, unknown> = {},
) {
const params = requireRecord(input, 'calendly')
const action = (typeof params.action === 'string' ? params.action : 'smoke-test') as CalendlyAction
const handler = actions[action]
if (!handler) {
throw new Error(
`Unsupported Calendly action: ${String(params.action)}. Use smoke-test, list-event-types, list-scheduled-events, or list-invitees.`,
)
}
return await handler(params as never)
}