import { i18n } from '@kbn/i18n' ; import { ml } from './ml_api_service' ; import { Calendar , CalendarId } from '../../../common/types/calendars' ; import { JobId } from '../../../common/types/anomaly_detection_jobs' ; class CalendarService { param calendar param jobId async assignNewJobId ( calendar , jobId ) { const { calendar_id : calendarId } = calendar ; try { await ml . updateCalendar ( { ... calendar , calendarId , job_ids : [ ... calendar . job_ids , jobId ] , } ) ; } catch ( e ) { throw new Error ( i18n . translate ( 'xpack.ml.calendarService.assignNewJobIdErrorMessage' , { defaultMessage : 'Unable to assign {jobId} to {calendarId}' , values : { calendarId , jobId } , } ) ) ; } } param calendarIds async fetchCalendarsByIds ( calendarIds ) { try { const calendars = await ml . calendars ( { calendarIds } ) ; return Array . isArray ( calendars ) ? calendars : [ calendars ] ; } catch ( e ) { throw new Error ( i18n . translate ( 'xpack.ml.calendarService.fetchCalendarsByIdsErrorMessage' , { defaultMessage : 'Unable to fetch calendars: {calendarIds}' , values : { calendarIds : calendarIds . join ( ', ' ) } , } ) ) ; } } } export const mlCalendarService = new CalendarService ( ) ;