import { BaseComponent, IValidationProperties, IRule } from './base-component'; enum ECurrencyValidatorType { GreaterThanCurrency = 'greaterThanCurrency', LessThanCurrency = 'lessThanCurrency', } interface ICurrencyValidationProperties extends IValidationProperties { min?: number; max?: number; } export class CurrencyComponent extends BaseComponent { protected override getValidatorFromRule(rule: IRule): ICurrencyValidationProperties | null { const mapping: Record = { max: ECurrencyValidatorType.LessThanCurrency, min: ECurrencyValidatorType.GreaterThanCurrency, }; const type = mapping[rule.name]; if (!type) { return null; } const argValue = rule.args?.limit ?? rule.arg; return { type, ...(type === ECurrencyValidatorType.LessThanCurrency ? { max: argValue } : {}), ...(type === ECurrencyValidatorType.GreaterThanCurrency ? { min: argValue } : {}), }; } protected override getMergedMetaProperties(): Record { const { prefix, ...meta } = super.getMergedMetaProperties(); if (prefix) { return { props: { prefix }, ...meta, }; } return meta; } }