import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import { GLOBAL_CALENDAR } from '../../../common/constants/calendars' ; import type { MlClient } from '../../lib/ml_client' ; type ScheduledEvent = estypes . MlCalendarEvent ; export class EventManager { private _mlClient : MlClient ; constructor ( mlClient ) { this . _mlClient = mlClient ; } async getCalendarEvents ( calendarId ) { const { body } = await this . _mlClient . getCalendarEvents ( { calendar_id : calendarId } ) ; return body . events ; } async getAllEvents ( jobId ? ) { const calendarId = GLOBAL_CALENDAR ; const { body } = await this . _mlClient . getCalendarEvents ( { calendar_id : calendarId , job_id : jobId , } ) ; return body . events ; } async addEvents ( calendarId , events ) { const body = { events } ; return await this . _mlClient . postCalendarEvents ( { calendar_id : calendarId , body , } ) ; } async deleteEvent ( calendarId , eventId ) { return this . _mlClient . deleteCalendarEvent ( { calendar_id : calendarId , event_id : eventId , } ) ; } isEqual ( ev1 , ev2 ) { return ( ev1 . event_id === ev2 . event_id && ev1 . description === ev2 . description && ev1 . start_time === ev2 . start_time && ev1 . end_time === ev2 . end_time ) ; } }