import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';

/**
 * Strictly checks numeric value is greater than `minValue` (not equal).
 * Empty values are treated as valid; combine with `Validators.required` when needed.
 */
export function greaterThanValidator(minValue: number): ValidatorFn {
  return (control: AbstractControl): ValidationErrors | null => {
    const v = control.value;
    if (v === null || v === undefined || v === '') {
      return null;
    }

    const numericValue = typeof v === 'number' ? v : Number(v);
    if (Number.isNaN(numericValue)) {
      return { greaterThan: 'مقدار باید عددی باشد' };
    }

    return numericValue > minValue
      ? null
      : {
          greaterThan: `مقدار باید بیشتر از ${minValue} باشد`,
        };
  };
}
