import { Injectable } from '@angular/core';

export type PASSWORD_MATCH_TYPE = 'MIN_8' | 'a-z' | 'A-Z';

@Injectable({
  providedIn: 'root',
})
export class RecoveryPasswordService {
  constructor() {}

  stringMatch(type: PASSWORD_MATCH_TYPE, value: string): boolean {
    if (!value) {
      return false;
    }
    let regex: RegExp;
    switch (type) {
      case 'a-z':
        regex = /^.*[a-z].*$/g;
        break;
      case 'A-Z':
        regex = /^(?=.*[A-Z0-9]).+$/g;
        break;
      case 'MIN_8':
        regex = /^.{8,}$/g;
        break;
    }
    return regex.test(value);
  }
}
