// Angular Core
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

// Services
import { ApiService } from '../../../../services/api/api.service';
@Injectable({
  providedIn: 'root'
})
export class LoginService {

  constructor(private http: HttpClient, public api: ApiService) { }

  /**
  * Authenticate password
  * @returns {object} promise
  */
  authenticateUser(deaNumber: string, password: string) {
    var loginCredentials = {};

    loginCredentials = {
      user_name: deaNumber,
      password: password,
      action: "login"
    };
    return this.api.create('/Authentication', loginCredentials);
  };

  /**
   * Authenticate Admin User
   * @returns {object} promise
  */
  authenticateAdminUser(userName: string, password: string) {
    return this.authenticateLogin(userName, password, 'adminLogin');
  };

  /**
   * 
   * @param string userName
   * @param string password
   * @param string action
   * @returns void
  */
  authenticateLogin(userName: string, password: string, action: string) {
      var loginCredentials = {};

      loginCredentials = {
          user_name : userName,
          password : password,
          action : action
      };
      return this.api.create('/Authentication',loginCredentials);
  };

  /**
   * sends respose to api service for handling
   * @param {object} response object
   * @returns {undefined}
   */
  errorCallBack(response: any) {
    this.api.errorCallback(response);
  };
}
