import { RuleTypeModel , RuleTypeParams , RuleTypeRegistryContract , } from '../../../triggers_actions_ui/public' ; import { ParsedTechnicalFields } from '../../../rule_registry/common/parse_technical_fields' ; import { AsDuration , AsPercent } from '../../common/utils/formatters' ; export type ObservabilityRuleTypeFormatter = ( options : { fields : ParsedTechnicalFields & Record < string , any > ; formatters : { asDuration : AsDuration ; asPercent : AsPercent ; } ; } ) => { reason : string ; link : string ; } ; export interface ObservabilityRuleTypeModel < Params extends RuleTypeParams = RuleTypeParams > extends RuleTypeModel < Params > { format : ObservabilityRuleTypeFormatter ; } export function createObservabilityRuleTypeRegistry ( ruleTypeRegistry ) { const formatters = [ ] ; return { register : ( type ) => { const { format , ... rest } = type ; formatters . push ( { typeId : type . id , fn : format } ) ; ruleTypeRegistry . register ( rest ) ; } , getFormatter : ( typeId ) => { return formatters . find ( ( formatter ) => formatter . typeId === typeId ) ?. fn ; } , } ; } export type ObservabilityRuleTypeRegistry = ReturnType < typeof createObservabilityRuleTypeRegistry > ;