import { assertEndpointId, fetchSessionizeView } from './client.ts'
import { projectSchedule } from './project.ts'
import type {
EndpointInput,
EventSchedule,
SessionizeScheduleDay,
} from './types.ts'
/**
* Load the Sessionize schedule grid as days, rooms, and time slots.
*
* @example
* import getSchedule from 'kody:@kody/sessionize/get-schedule'
* const schedule = await getSchedule({ endpointId: 'jl4ktls0' })
* // => { days: [{ date: '2023-09-16T00:00:00Z', slots: [...] }] }
*/
export default async function getSchedule(
input: EndpointInput,
): Promise<EventSchedule> {
const endpointId = assertEndpointId(input.endpointId)
const days = await fetchSessionizeView<Array<SessionizeScheduleDay>>({
endpointId,
view: 'GridSmart',
})
return projectSchedule(endpointId, days)
}