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

@Injectable()
export class ValidationService {

  // {code: "auth/invalid-email", message: "The email address is badly formatted."}
  errorList  = {
  "auth/invalid-email" : "Invalid Email address",
    "auth/email-already-in-use": "This Email id is already taken",

    "required" : 'This field is required',
    "email":  "Please enter a valid email",
    "minLength": "Minimum characters length is ",
  "maxLength": "Maximum characters length is ",
  "match": "Password not match",
  "alphabets": "Only alphabets are allowed ",
  "numeric": "Only numbers are allowed",
  "alphanumeric" : "Only alphanumeric characters are allowed",
  "website": "Please enter a valid website address",
   "min": "Minimum value is ",
   "extension": "Not a valid extension",
   "max": "Maximum value is ",
  }		
  

  constructor( ) {
  	console.log("ValidationService called")
  }

  /* Get all error list obj
  ================================== */
  getErrorList(){
    return this.errorList;
  }
  
  /* check whether the error code having our definition else return firebase definition
  ================================== */
  getError(error:any):string{                        // Argument = error object
    
    if(this.errorList.hasOwnProperty(error.code)){  // check whether the error code having our definition 
      return this.errorList[error.code]  // return our definition
    }else{
      return error.message; // 
    }
  }

  
}
