import { ENVIRONMENT_ALL } from '../environment_filter_values' ; import { Environment } from '../environment_rt' ; import { ApmMlDetectorType } from './apm_ml_detectors' ; import { ServiceAnomalyTimeseries } from './service_anomaly_timeseries' ; export function getPreferredServiceAnomalyTimeseries ( { environment , environments , detectorType , allAnomalyTimeseries , fallbackToTransactions , } ) { const seriesForType = allAnomalyTimeseries . filter ( ( serie ) => serie . type === detectorType ) ; const preferredEnvironment = environment === ENVIRONMENT_ALL . value && environments . length === 1 ? environments [ 0 ] : environment ; return seriesForType . find ( ( serie ) => serie . environment === preferredEnvironment && ( fallbackToTransactions ? serie . version <= 2 : serie . version >= 3 ) ) ; }