import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';

export class FormValidations  {

  static maxDiscount(discountUser: number) {

    const validator = (formControl: AbstractControl) => {

      if (!formControl.root || (formControl.root as FormGroup).controls) {
        return null;
      }
      const mDiscount = formControl.value;
      console.log('Desconto informado: ' + mDiscount);
      console.log('desconto autorizado: ' + discountUser);
      if (mDiscount > discountUser) {
        console.log('controle invalido');
        return { maxDiscount : true };
      }
      return null;
    };

    return validator;
  }
}
