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

export class EmployeeValidator {
  static HasSelectedAtLeastOneRole(roleFormControlNames: Array<string>): ValidatorFn {
    return (fg: FormGroup): { [key: string]: unknown } => {
      if (!roleFormControlNames || roleFormControlNames.length === 0) {
        return { noRoleSelected: true };
      }

      return roleFormControlNames.some(roleFormControlName => fg?.controls[roleFormControlName]?.value)
        ? null
        : { noRoleSelected: true };
    };
  }
}
