import { Injectable } from '@angular/core';
import { Http, Response, ResponseType } from '@angular/http';
import { Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/toPromise';
import { Router } from '@angular/router';
import { environment } from '../../environments/environment.dev';
import { ResponseContentType } from '@angular/http';

const baseResponse = { status: '', message: '', data: null };

@Injectable()

export class AuthService {

  // Base Url
  private baseURL = environment.apiUrl;

  // service Url and End Point Details..
  private socialLoginUrl = this.baseURL + 'security/oauth2/getTokenByAuthCode?redirectURI=';
  private socialLoginUrlNew = this.baseURL + 'security/oauth2/getAccessToken/';
  private getSocialLoginsUrl = this.baseURL + 'security/oauth2/login/';
  private LoginUrl = this.baseURL + 'security/oauth2/loginWithDatabase/';
  private signupUrl = this.baseURL + 'orchestrate/candidate-signup/';
  private studentSignupUrl = this.baseURL + 'orchestrate/student-signup/'
  private checkEmailUrl = this.baseURL + 'orchestrate/employee-verifyUserPresence/:email';
  private getUserDetailSocialAuthUrl = this.baseURL + 'orchestrate/userDetailsForSocialAuth/';
  private getUserDetailDBAuthUrl = this.baseURL + 'orchestrate/userDetailsForDBAuth/';
  private dashBoardUrl = this.baseURL + 'orchestrate/dashboard/';
  private logoutUrl = this.baseURL + 'orchestrate/logout/';
  private emailVerfUrl = this.baseURL + 'orchestrate/dbuser-forgotPassword/:email/';
  private userPassUpdUrl = this.baseURL + 'orchestrate/dbuser-changePassword/';
  private studentEmailVerfUrl = this.baseURL + 'orchestrate/student-generatePasscode/:email/';
  private applnFeedbackUrl = this.baseURL + 'orchestrate/feedback-createFeedback/';

  // BNYM New Api's
  private getCourseNuseCasesUrl = this.baseURL + 'orchestrate/course-getAllCoursesBySkillMstr/:values';

  /**  This API URL are scheduling and register the client in mettle**/
  private onBoardUrl = this.baseURL + 'orchestrate/ta-onboardCandidate/';
  private scheduleUrl = this.baseURL + 'orchestrate/screening-createSchedule/';
  private registerUrl = this.baseURL + 'orchestrate/screening-registerCandidate/';
  private getResultUrl = this.baseURL + 'orchestrate/screening-getCandidateResult/';
  private searchUrl = this.baseURL + 'orchestrate/candidate-findUserInfo/';
  private findUserInfoByUrl = this.baseURL + 'orchestrate/candidate-findUserInfoBy/';
  private getSkillUrl = this.baseURL + 'orchestrate/screening-getSkillDetails/';
  private getAssessmentUrl = this.baseURL + 'orchestrate/admin-getAssessmentDetails/';
  private getAssessmentDetailsBySkillTrackDtlsName = this.baseURL + 'orchestrate/admin-getAssessmentDetailsBySkillTrackDtlsName/';
  private getAssessmentTechnicalcaseName = this.baseURL + 'orchestrate/common-getAllTechnicalUsecasesBySkill/';
  private getAssessmentBusinesscaseName = this.baseURL + 'orchestrate/common-getAllBusinessUsecasesBySkill/';
  private getAllAssessmentDtlsUrl = this.baseURL + 'orchestrate/screening-getAllAssessmentDtls/';
  private getSchedulesUrl = this.baseURL + 'orchestrate/screening-getAllSchedule/';
  private getSetupWorkSpaceUrl = this.baseURL + 'orchestrate/setupWorkspace/';
  private getWorkspaceIdUrl = this.baseURL + 'orchestrate/getWorkSpaceIdBy/';
  private getCandidateDashboardUrl = this.baseURL + 'orchestrate/dashboard/';
  private getUserDetailsUrl = this.baseURL + 'orchestrate/getUserDetails/';
  private getEmployeeDashboardUrl = this.baseURL + 'orchestrate/employee-getEmployeeDetails/';
  private getAllCoachCandidatesUrl = this.baseURL + 'orchestrate/pgManager-getAllCoachCandidates/';
  private getCandidateUrl = this.baseURL + 'orchestrate/dashboard/';
  private getCandidatePrimaryEvaluationReportUrl = this.baseURL + 'orchestrate/screening-getCandidateResult/';
  private getEmployeeCourseResult = this.baseURL + 'orchestrate/screening-getEmployeeCourseResult/';
  private getEmployeeMiniAssessmentResult = this.baseURL + 'orchestrate/screening-getEmployeeAssessmentResult';
  private getAllCoachesforCandidateUrl = this.baseURL + 'orchestrate/pgManager-getAllCoaches/';
  private getAllCandidatesUrl = this.baseURL + 'orchestrate/pgManager-getAllCandidatesForPgManager/';
  private getAllEmployeeUrl = this.baseURL + 'orchestrate/employee-getAllEmployee/';
  private getRecommendedCourseUrl = this.baseURL + 'orchestrate/courseUser-getActiveRecommendedCoursesForAll/';
  private submitAssignCoachCandidateUrl = this.baseURL + 'orchestrate/pgManager-assignCoachToCandidate/';
  private getUnassignedCandidatesUrl = this.baseURL + 'orchestrate/pgManager-getAllUnassignedCandidates/';
  private getAllCoachesForAssignedCandidatesUrl = this.baseURL + 'orchestrate/pgManager-getAllCoachesCandidates';
  private getAllCoachesForApplicationUrl = this.baseURL + 'orchestrate/coach-getAllCoachApplications/';
  private getcandidateChallangeStatusUrl = this.baseURL + 'orchestrate/taPgm-updateStatus/';
  private describeWorkspacesUrl = this.baseURL + 'orchestrate/describeWorkspaces/';
  private getCandDetailsUrl = this.baseURL + 'orchestrate/candidate-dashboard/';
  private getCandidateFeedbackUrl = this.baseURL + 'orchestrate/candidate-getFeedbacksByCandidateUserIdAndLevel/:candidateUserId/:level';
  private postCandidateFeedbackUrl = this.baseURL + 'orchestrate/candidate-submitCandidateReviewFeedback/';

  /*  PGM & COACH API URLS */
  private getCandidateUpdateStatusUrl = this.baseURL + 'orchestrate/taPgm-updateStatus/';
  private getAllCoachesforPgmUrl = this.baseURL + 'orchestrate/pgManager-getAllCoachesByUsersSkillTrackMstrId/';
  private getAllAssessmentforPgmUrl = this.baseURL + 'orchestrate/common-getAllUsecaseByUserInfoMstrId/';
  private getFeedBacksUrl = this.baseURL + 'orchestrate/candidate-submitCandidateReviewFeedback/';
  private getCoachUpdateUrl = this.baseURL + 'orchestrate/pgManager-updateCoach/';
  private getAssessmentUpdateUrl = this.baseURL + 'orchestrate/pgManager-updateUseCase/';



  /* TA Flow API Url's*/
  private getInviteUrl = this.baseURL + 'orchestrate/TA-initiatePg/';
  private getAllUserDetailsUrl = this.baseURL + 'orchestrate/oldTA-getAllRegisteredCandidates/';
  private getAllCandidateListUrl = this.baseURL + 'orchestrate/candidates-getCandidatesByFilter/';
  private getcandidateStatusUpdateUrl = this.baseURL + 'orchestrate/common-updateStatus/';
  private getCandidateRegisterUrl = this.baseURL + 'orchestrate/ta-onboardCandidate/';
  private getCandidateUpdateUrl = this.baseURL + 'orchestrate/ta-updateCandidate/';
  private getupdateCoachCommentsUrl = this.baseURL + 'orchestrate/coach-updateCoachComments/';
  private getLocationsUrl = this.baseURL + 'orchestrate/admin-getAllActiveLocation/';
  private getFetchAllTAUrl = this.baseURL + 'orchestrate/admin-fetchAllTA/';
  private getReportFilterUrl = this.baseURL + 'orchestrate/report/pgReports-candidateReport/';
  private getEmployeeReportFilterUrl = this.baseURL + 'orchestrate/report/capabilityTransformation/';
  private getFileUploadUrl = this.baseURL + 'orchestrate/uploadFile/';
  private getEditFileUrl = this.baseURL + 'orchestrate/editFile/';
  private getFileUrl = this.baseURL + 'orchestrate/getFileContent/';
  private candidateRescheduleUrl = this.baseURL + 'orchestrate/screening-rescheduleMettlTest/';
  private postMapProfilePicToCandidateUrl = this.baseURL + 'orchestrate/common_uploadProfilePhoto/';
  private getCandidateInfoUrl = this.baseURL + 'orchestrate/TA-getCandidate/';
  private getCandidateReportUrl = this.baseURL + 'orchestrate/pgReports-candidateWebReport/';
  private getFeedbackReportUrl = this.baseURL + 'orchestrate/candidate-getFeedbackReport/';
  private getCandidateCheckedInReport = this.baseURL + 'orchestrate/candidatecheckin-getCheckedInCandidatesWebReport/';
  private getFeedbackReportDownloadingUrl = this.baseURL + 'api/candidate/downloadFeedbackReport';
  private getCandidatecheckinDownloadingUrl = this.baseURL + 'candidatecheckin/validationtest/downloadReport';

  /* ADMIN FLOW API Url's */

  private getAllUserCountUrl = this.baseURL + 'orchestrate/admin-getAllUserCount/';
  private getAllAssessmentUrl = this.baseURL + 'orchestrate/admin-getAllJobRequirement/';
  private getAllExperienceLevelUrl = this.baseURL + 'orchestrate/common-getAllExperienceLevel/';
  private getAllRoleUrl = this.baseURL + 'orchestrate/admin-getAllRole/';
  private getAllRolePrivilegeUrl = this.baseURL + 'orchestrate/admin-getAllRolePrivilege/';
  private getPopulateRoleBasedPrivilegeUrl = this.baseURL + 'orchestrate/admin-populateRoleBasedPrivilege/';
  private getAllLocationUrl = this.baseURL + 'orchestrate/admin-getAllActiveLocation/';
  private getAllAwsDirectoryBundleUrl = this.baseURL + 'orchestrate/admin-getAllAwsDirectoryBundle/';
  private getAllUserUrl = this.baseURL + 'orchestrate/admin-getAllUser/';
  private getTransferCandidateUrl = this.baseURL + 'orchestrate/admin-transferCandidate/';
  private getAddRoleUrl = this.baseURL + 'orchestrate/admin-addRole/';
  private getEditRoleUrl = this.baseURL + 'orchestrate/admin-updateRole/';
  private getAddSkillUrl = this.baseURL + 'orchestrate/admin-addLocation/';
  private getAddLocationUrl = this.baseURL + 'orchestrate/admin-addLocation/';
  private getAddEmployeeUrl = this.baseURL + 'orchestrate/admin-transferCandidate/';
  private getaddAssessmentDetailsUrl = this.baseURL + 'orchestrate/admin-addAssessmentDetails/';
  private getaddAWSDirecBundleUrl = this.baseURL + 'orchestrate/admin-addAWSDirecBundle/';
  private getaddNewUserUrl = this.baseURL + 'orchestrate/admin-addNewUser/';
  private getEditUserUrl = this.baseURL + 'orchestrate/admin-updateUser/';
  private getTranferCandidateUrl = this.baseURL + 'orchestrate/admin-transferCandidate/';
  private getnominateCoachUrl = this.baseURL + 'orchestrate/admin-nominateCoach/';
  private getassignRoleToUserUrl = this.baseURL + 'orchestrate/admin-assignRoleToUser/';
  private getAllSkillUrl = this.baseURL + 'orchestrate/common-getAllSkillTrackDtls/';
  private getAllSkillTrackMstrUrl = this.baseURL + 'orchestrate/admin-getAllSkillTrackMstr/';
  private getAllMettlAssessmentDtlsUrl = this.baseURL + 'orchestrate/screening-getAllMettlAssessmentDtls/';
  private getAllLearningPathsUrl = this.baseURL + 'orchestrate/learningPath/';
  private deleteLearningPathUrl = this.baseURL + 'orchestrate/learningPath/:learningPathId/:userInfoMstrId';
  private getAllSkillTrackMstrAndDtlsUrl = this.baseURL + 'orchestrate/admin-getAllSkillTrackMstrAndDtls/'

  private getAllTechnicalUseCaseListUrl = this.baseURL + 'orchestrate/common-getAllMiniUsecasesBySkill/';
  private getAllBussniessUseCaseListUrl = this.baseURL + 'orchestrate/common-getAllMainUsecasesBySkill/';
  private getRecommendAssessmentUrl = this.baseURL + 'orchestrate/employee-recommendAssessment/';

  private getsearchUserUrl = this.baseURL + 'orchestrate/admin-searchUser/';
  private getActiveLocationByUrl = this.baseURL + 'orchestrate/admin-getActiveLocationBy/';
  private getAllSkillTrackDetailsByUrl = this.baseURL + 'orchestrate/admin-getAllSkillTrackDetailsBy/';
  private getUsecaseUrl = this.baseURL + 'orchestrate/admin-getUsecase/';
  private getCCindexUrl = this.baseURL + 'orchestrate/common-getAllEventCapabilitiesByEventId/';
  private getDeleteAssessmentIdUrl = this.baseURL + 'orchestrate/admin-deleteAssessmentdtls/';
  private getDeleteAwsDirecBundleUrl = this.baseURL + 'orchestrate/admin-deleteAwsDirecBundle/';
  private getDeleteSkillDtlsUrl = this.baseURL + 'orchestrate//';
  private getDeleteLocationUrl = this.baseURL + 'orchestrate/admin-deleteLocation/';
  private getDeleteRoleUrl = this.baseURL + 'orchestrate/admin-deleteRole/';
  private getUpdateAssessmentDetailsUrl = this.baseURL + 'orchestrate/admin-updateAssessmentDetails/';
  private getUpdateAWSDirecBundleUrl = this.baseURL + 'orchestrate/admin-updateAWSDirecBundle/';
  private getUpdateLocationUrl = this.baseURL + 'orchestrate/admin-updateLocation/';
  private getUpdateSkillTrackDetailsUrl = this.baseURL + 'orchestrate/admin-updateSkillTrackDetails/';
  private getaddMultiUserCoursesUrl = this.baseURL + 'orchestrate/recommendCourse/';
  private getaddEmployeeEventDetailsUrl = this.baseURL + 'orchestrate/employee-addEventDetails/';
  private getAssignCoachForEmployeeUrl = this.baseURL + 'orchestrate/employee-assignCoachDetails';
  private getEmployeeCourseMappingUrl = this.baseURL + 'orchestrate/dashboard//';
  private getEmployeeAssessmentsUrl = this.baseURL + 'orchestrate/employee-fetchEmployeeEvents/';
  private getAllSkillCategoryUrl = this.baseURL + 'orchestrate/admin-getAllSkillCategory/';
  private getReviewDetails = this.baseURL + 'orchestrate/employee-getEventDetailsAndReviewerDetailsByEventDtlsId/'
  private getAllJobRequirementsUrl = this.baseURL + 'orchestrate/admin-getAllJobRequirementDetails/';
  // private getAllWhiteBoardUcUrl = this.baseURL + 'api/common/getAllWhiteBoardUsecasesBySkill/';
  private getAllCodingChallangeUcUrl = this.baseURL + 'orchestrate/common-getAllCodingChallengeUsecasesBySkill/';
  private getAllCaccountsUrl = this.baseURL + 'orchestrate/admin-getAllAccounts/';
  private getaddJobRequirementUrl = this.baseURL + 'orchestrate/admin-addJobRequirement/';
  private geteditJobRequirementUrl = this.baseURL + 'orchestrate/admin-updateJobRequirement/';
  private deleteJobRequirementUrl = this.baseURL + 'orchestrate/admin-deleteJobRequirement/:requirementId';
  private getAllAwsDirectoryBundleBySkillUrl = this.baseURL + 'orchestrate/admin-getAwsDirectoryBundleBySkills/';
  private getCoachesBySelectedSkillsUrl = this.baseURL + 'orchestrate/pgManager-getAllCoachesBySkillTrackMstrId/';
  private getAllInnovationCatsUrl = this.baseURL + 'orchestrate/admin-getAllInnovationCats/';
  private addInnovationCatUrl = this.baseURL + 'orchestrate/admin-addInnovationCat/';
  private delInnovationCatUrl = this.baseURL + 'orchestrate/admin-deleteInnovationCats/:categoryId';
  private getAllCollegesUrl = this.baseURL + 'orchestrate/collegeList/';
  private delCollegeUrl = this.baseURL + 'orchestrate/collegeList/:adminId/:collegeId';
  private getInactiveCollegesUrl = this.baseURL + '/orchestrate/collegeList/?status=InActive';

  /* workspaces*/
  private describeWorkspaceUrl = this.baseURL + 'orchestrate/describeWorkspaces/';
  private startWorkspacesUrl = this.baseURL + 'orchestrate/startWorkspaces/';

  /* coach employee*/
  private getAllEmployeesForCoachUrl = this.baseURL + 'orchestrate/employee-getAllEmployeesForCoach/';
  private getEmployeeUrl = this.baseURL + 'orchestrate/employee-getEmployeeEventDetailsForCourse/';
  private getEmployeeStatusUpdateUrl = this.baseURL + 'orchestrate/employee-updateCourseStatus/';
  private getEmployeeCourseByIdUrl = this.baseURL + 'orchestrate/getCourseByCourseId/';
  private getEmployeeUsecaseUrl = this.baseURL + 'orchestrate/getEmployeeUsecase/';
  private getCoachStatusUpdateUrl = this.baseURL + 'orchestrate/coach-updateCoachStatus/';

  /* coach employee*/
  private updateAwsWorkspaceStatusUrl = this.baseURL + 'orchestrate/aws-updateAwsWorkspaceStatus/:adId/:status';
  private getTerminateAwsWorkspaceUrl = this.baseURL + 'orchestrate/terminateWorkspaces/';
  private getEmployeeAssessmentStatusUrl = this.baseURL + 'orchestrate/employee-getEmployeeEventsDtls/';
  private getAllEmployeeAssessmentsNewUrl = this.baseURL + 'orchestrate/employee-getAllEmployeeEventsDtls/';
  private getAllEmployeeAssessmentsUrl = this.baseURL + 'orchestrate/employee-getEmployeeEventsDtls/';
  private getEmployeeCourseUrl = this.baseURL + 'orchestrate/courseUser-byStatus/';
  /* Employee flow - Innovation*/
  private getInnovationDetail = this.baseURL + 'orchestrate/employee-getInnovationDetail/';

  /*BNYM API */
  private getAllListOfEmployeeUrl = this.baseURL + 'orchestrate/employee-getAllEmployees/';
  private getGITuserDetailsUrl = this.baseURL + 'orchestrate/gitLab-createProject/';
  private getOneGitUserUrl = this.baseURL + 'orchestrate/gitLab-getOneUser/';
  private getUserSonarReportUrl = this.baseURL + 'orchestrate/gitLab-getSonarReportUrl/';
  private getEmployeeAssessmentUrl = this.baseURL + 'orchestrate/employee-getEmployeeAssessmentDtls/';
  private updateAssessmentStatusUrl = this.baseURL + 'orchestrate/employee-updateAssessmentStatus/';
  private getSubmitForRevieUrl = this.baseURL + 'orchestrate/employee-submitForReview/';
  private getAllCapabilityAssessmentsUrl = this.baseURL + 'orchestrate/admin-getAllCapabilityAssessments/';
  private getCapabilityAssessmentsBySkillUrl = this.baseURL + 'orchestrate/admin-getPgAssessmentDtlsBySkills/';
  private getSelfAssessmentUrl = this.baseURL + 'orchestrate/employee-selfAssessment/';
  private getAllAssesmentsByIdUrl = this.baseURL + 'orchestrate/screening-getAllAssesmentsById/';
  private getCourseByCourseIdsUrl = this.baseURL + 'orchestrate/course-getCourses/';
  private getaddUserCoursesUrl = this.baseURL + 'orchestrate/courseUser-user/';
  private getReviewerDetailsUrl = this.baseURL + `orchestrate/employee-getReviewScore/?eventDtlsId=:eventDtlsId`;
  private getAllPgMgrsUrl = this.baseURL + 'orchestrate/pgManager-getAllPgManagers/';

  /**
   * New API's For Unified Login/Sign Up
   */
  private verifyEmailId = this.baseURL + 'orchestrate/auth-verify/';
  private registerCandidateUrl = this.baseURL + 'orchestrate/auth-signup/';
  private registerStudentUrl = this.baseURL + 'orchestrate/auth-register/';

  // Declearation Part here...
  results: string[];
  data: Object;
  userData: any;
  signupData: any;
  loginData: any;
  emailVdata: any;

  errorData: {
    errorBean: {
      errorMessage: string[],
      'errorCode': string[],
      'code': string[],
      'message': string[]
    },
    pgUserInfoDtls: string[]
  };

  errorResp: {
    error: {
      message: string[],
      code: string[]
    }
  };

  creatWorkspaceData: any;
  startWorkspaceData: any;

  // constructor(private http: Http, private router: Router) {
  constructor(private http: Http, private router: Router) {
  }

  // Handling the Error function here...
  public handleError(err) {
    let errData;
    console.log(err.status);
    console.log(err._body);

    if (err.status === 400) {
      errData = JSON.parse(err._body);
      console.log(errData.error);
      if (errData.error) {
        return { ...baseResponse, status: 'error', message: errData.error.message };
      } else if (errData.errorBean) {
        return { ...baseResponse, status: 'error', message: errData.errorBean.message };
      }
    } else if (err.status === 403) {
      errData = JSON.parse(err._body);
      console.log(errData.error);
      return { ...baseResponse, status: 'error', message: errData.error.message };
    } else if (err.status === 502) {
      errData = JSON.parse(err._body);
      console.log(errData.error);
      this.router.navigate(['severStop']);
    } else if (err.status === 500) {
      errData = JSON.parse(err._body);
      console.log(errData.error);
      return { ...baseResponse, status: 'error', message: errData.error.message };
    } else {
      errData = JSON.parse(err._body);
      console.log(errData.error);
      if (errData.error.message) {
        return { ...baseResponse, status: 'error', message: errData.error.message };
      }
      else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }
    }

  }

  /***** ==================> Service function start Here... <================ *****/
  /*Logout Api Funcction here*/
  logout(userData) {
    const output = 'success';
    return this.http.post(this.logoutUrl, userData).toPromise().then(response => {
      this.signupData = response;
      if (this.signupData.status === 200) {
        return { status: 'success', message: 'logout successfully' };
      } else if (this.signupData.status === 403) {
        // return {status:'error',message:'Failed to save Details...!'}
        return { status: 'success', message: 'logout successfully' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // socail login Authentication
  socialLogin(log) {
    const code = log.code;
    const url = log.redirectUrl + '/&idpType=facebookIdentity&code=';
    const output = 'success';
    return this.http.get(this.socialLoginUrl + url + code).toPromise().then(response => {
      this.loginData = response.json();
      console.log(this.loginData);
      console.log(this.loginData['access_token']);

      if (response.status === 200 && this.loginData['access_token']) {
        return { status: 'success', accessToken: this.loginData['access_token'] };
      } else if (this.loginData.status === 400) {
        return { status: 'error', message: 'Invalid credentials...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      console.log(err);
      this.loginData = err;
      console.log(this.loginData.status);
      if (this.loginData.status <= 199 || this.loginData.status >= 500) {
        return { status: 'error', message: 'Something went wrong...!' };
      } else {
        this.errorResp = JSON.parse(this.loginData._body);
        console.log(this.errorResp.error.message);
        if (this.loginData.status === 400) {
          console.log('íf inside');
          return { status: 'error', message: this.errorResp.error.message };
        } else if (this.loginData.status === 403) {
          console.log('íf inside');
          return { status: 'error', message: this.errorResp.error.message };
        } else {
          console.log('else');
          return { status: 'error', message: 'Something went wrong...!' };
        }
      }
    });
  }

  socialLoginNew(log) {
    console.log(log, 'Request GetAccess Tokken');
    const output = 'success';
    return this.http.post(this.socialLoginUrlNew, log).toPromise().then(response => {
      console.log(response.status);
      console.log(response['_body']);
      if (response.status === 200) {
        const resData = JSON.parse(response['_body']);
        console.log(resData);
        if (resData.errors) {
          if (resData.userInfo !== {}) {
            return { status: 'error', message: 'somthing went wrong...!' };
          } else {
            return { status: 'error', message: resData.errors };
          }
        } else {
          return { status: 'success', accessToken: resData.tokenVO.access_token };
        }
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      console.log(err);
      this.loginData = err;
      console.log(this.loginData.status);
      if (this.loginData.status <= 199 || this.loginData.status >= 500) {

        return { status: 'error', message: 'Something went wrong...!' };
      } else {
        this.errorResp = JSON.parse(this.loginData._body);
        console.log(this.errorResp.error.message);
        if (this.loginData.status === 400) {
          console.log('íf inside');
          return { status: 'error', message: this.errorResp.error.message };
        } else if (this.loginData.status === 403) {
          console.log('íf inside');
          return { status: 'error', message: this.errorResp.error.message };
        } else {
          console.log('else');
          return { status: 'error', message: 'Something went wrong...!' };
        }
      }
    });
  }

  // Login for db authentication service
  login(userData) {
    const output = 'success';
    return this.http.post(this.LoginUrl, userData).toPromise().then(response => {
      this.loginData = response;
      if (this.loginData.status === 200) {
        const loginSts = JSON.parse(this.loginData._body);
        if (loginSts.tokenVO.error) {
          return { status: 'error', message: 'Entered Mail ID/Password is incorrect' };
        } else {
          return { status: 'success', data: JSON.parse(this.loginData._body) };
        }
      } else if (this.loginData.status === 400) {
        return { status: 'error', message: this.errorResp.error.message };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  checkEmailAdr(email) {
    const output = 'success';
    console.log("auth service email: ", email);
    return this.http.get(this.checkEmailUrl.replace(':email', email)).toPromise().then(response => {
      this.emailVdata = response;
      return JSON.parse(this.emailVdata._body);
    }).catch(this.handleError);
  }

  // SignUp for db authentication service
  signup(userData) {
    const output = 'success';
    return this.http.post(this.signupUrl, userData).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  getEmailVerification(userData) {
    const output = 'success';
    return this.http.get(this.emailVerfUrl.replace(':email', userData)).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  //Student Signup
  studentSignup(userData) {
    const output = 'success';
    return this.http.post(this.studentSignupUrl, userData).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  stuEmailVerification(userData) {
    const output = 'success';
    return this.http.get(this.studentEmailVerfUrl.replace(':email', userData)).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }
  updateUserPassword(userData) {
    const output = 'success';
    return this.http.post(this.userPassUpdUrl, userData).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  // User Details for db and Soical authentication service
  userDetails(userData) {
    const output = 'success';
    return this.http.post(this.getUserDetailsUrl, userData).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return this.userData._body;
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Invalid Access...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // candidate challange status detils
  getCandidateChallangeStatus(userData) {
    return this.http.put(this.getcandidateChallangeStatusUrl, userData).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return this.userData._body;
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Invalid Access...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }
  // candidate dashboard orchestrate describeWorkspaces/
  describeWorkspaces(data) {
    return this.http.post(this.describeWorkspacesUrl, data).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return this.userData._body;
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Invalid Access...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // DashBoard authentication service
  dashBoardDetails(user) {
    const output = 'success';
    return this.http.post(this.dashBoardUrl, user).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return this.userData._body;
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getResultDetails(result) {
    const output = 'success';
    return this.http.post(this.getResultUrl, result).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return this.userData._body;
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // Schedule Create Service
  onboardTA(schedule) {
    const output = 'success';
    return this.http.post(this.onBoardUrl, schedule).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // Schedule Create Service
  scheduleCreate(schedule) {
    const output = 'success';
    return this.http.post(this.scheduleUrl, schedule).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // getWorkspaceId Create Service
  getWorkspaceId(schedule) {
    const output = 'success';
    return this.http.post(this.getWorkspaceIdUrl, schedule).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  // Register user Service
  registerUser(user) {
    const output = 'success';
    return this.http.post(this.registerUrl, user).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  searchUser(schedule) {
    const output = 'success';
    return this.http.post(this.searchUrl, schedule).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getUserInfoBy(id) {
    const output = 'success';
    return this.http.get(this.findUserInfoByUrl + id.adId).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to schedule the Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getCourseNuseCases(values) {
    const output = 'success';
    return this.http.get(this.getCourseNuseCasesUrl.replace(':values', values)).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getSkill() {
    const output = 'success';
    return this.http.get(this.getSkillUrl).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getAllSkill() {
    const output = 'success';
    return this.http.get(this.getAllSkillUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllSkillCategory() {
    const output = 'success';
    return this.http.get(this.getAllSkillCategoryUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllCapabilityAssessments() {
    const output = 'success';
    return this.http.get(this.getAllCapabilityAssessmentsUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCapabilityAssessmentsBySkill(id) {
    const output = 'success';
    return this.http.get(this.getCapabilityAssessmentsBySkillUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCandDetails(id) {
    const output = 'success';
    return this.http.get(this.getCandDetailsUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCandidateFeedback(candidateUserId: any, level: any) {
    // .replace(':learningPathId', learningPathId).replace(':userInfoMstrId', userInfoMstrId), null
    const output = 'success';
    return this.http.get(this.getCandidateFeedbackUrl.replace(':candidateUserId', candidateUserId).replace(':level', level), null).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  submitCandFeedback(fdbk) {
    const output = 'success';
    return this.http.post(this.postCandidateFeedbackUrl, fdbk).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  submitApplnFeedback(fdbk) {
    const output = 'success';
    return this.http.post(this.applnFeedbackUrl, fdbk).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getTestDetails(id) {
    const output = 'success';
    return this.http.post(this.getCandidateDashboardUrl, id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getEmployeeTestDetails(id) {
    const output = 'success';
    return this.http.get(this.getEmployeeDashboardUrl + id + '/').toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllUserCount() {
    return this.http.get(this.getAllUserCountUrl).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getAssessmentDetails(list) {
    const output = 'success';
    const url = this.getAssessmentUrl + list;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }
  getAssessmentSkillDetails(list) {
    const output = 'success';
    const url = this.getAssessmentDetailsBySkillTrackDtlsName + list;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getAssessmentTechnicalcase(list) {
    const output = 'success';
    const url = this.getAssessmentTechnicalcaseName + list;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getAssessmentBusinesscase(list) {
    const output = 'success';
    const url = this.getAssessmentBusinesscaseName + list;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }


  getEmployeeAssessmentDetails(data) {
    const output = 'success';
    const url = this.getEmployeeAssessmentUrl + data.eventId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getSchedules() {
    const output = 'success';
    return this.http.get(this.getSchedulesUrl).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  getLocations() {
    return this.http.get(this.getLocationsUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }


  /* Get Job Requirement */
  getAllJobRequirements() {
    const output = 'success';
    return this.http.get(this.getAllJobRequirementsUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getFetchAllTA() {
    return this.http.get(this.getFetchAllTAUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getSocialLogins(data) {
    return this.http.post(this.getSocialLoginsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getUserDetails(user) {
    const output = 'success';
    return this.http.post(this.getUserDetailsUrl, user).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  /*TA Flow API Service Here Only */
  getAllCandidates(userId) {
    const output = 'success';
    return this.http.get(this.getAllUserDetailsUrl + userId).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  getAllCandidateLists(data, state) {
    const output = 'success';
    return this.http.post(this.getAllCandidateListUrl + state, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*GET CANDIDATE REPORT API*/

  getCandidateReport(data) {
    const output = 'success';
    return this.http.post(this.getCandidateReportUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getFeedBacks(data) {
    const output = 'success';
    return this.http.post(this.getFeedBacksUrl, data).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: "FeedBack submited successfully" };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getAllEmployee(userId, data) {
    const output = 'success';
    return this.http.post(this.getAllEmployeeUrl + userId, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  getAllListOfEmployee(userId, data) {
    const output = 'success';
    return this.http.get(this.getAllListOfEmployeeUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getRecommendedCourses(email, userId) {
    const output = 'success';
    return this.http.get(this.getRecommendedCourseUrl + email + '/' + userId + '/').toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  coachStatusUpdate(id, status) {
    const output = 'success';
    return this.http.get(this.getCoachStatusUpdateUrl + id + '/' + status).toPromise().then(response => {
      console.log(response, 'Status Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      let errData;
      console.log(err.status);
      console.log(err._body);

      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 500) {
        errData = JSON.parse(err._body);
        console.log(err._body);
        const pattfb = new RegExp('TA_APPROVED performed successfully');
        const resfb = pattfb.test(err._body);
        const pattfr = new RegExp('TA_REJECTED performed successfully');
        const resfr = pattfr.test(err._body);
        if (resfb) {
          // alert("TA_APPROVED performed successfully");
          // window.location.href = window.location.origin+'/taProfile?'+'uuid='+user.toId
        } else if (resfr) {
          // alert("TA_REJECTED performed successfully");
          // window.location.href = window.location.origin+'/ta'
        } else {
          return { status: 'error', message: errData.error.message };
        }
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  getInvite(user) {
    const output = 'success';
    return this.http.post(this.getInviteUrl, user).toPromise().then(response => {
      console.log(response, 'Status Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', message: "PG Initiated Successfully" };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getUpdateCandidateStatus(data) {
    const output = 'success';
    return this.http.put(this.getCandidateUpdateStatusUrl, data).toPromise().then(response => {
      console.log(response, 'Status Updates');
      this.userData = response;
      console.log("_body -- ", this.userData._body);
      this.userData._body = JSON.parse(this.userData._body);
      console.log("_body -- ", this.userData._body);
      if ((this.userData.status === 200) && !(this.userData._body.errorBean)) {
        return { status: 'success', message: "Updated Successfully !!" };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to Update Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getUpdateCoach(data, path) {
    const output = 'success';
    return this.http.put(this.getCoachUpdateUrl + path + '/', data).toPromise().then(response => {
      console.log(response, 'Coach Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', message: "Updated Successfully !!" };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to Update Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getUpdateAssessment(data) {
    const output = 'success';
    return this.http.put(this.getAssessmentUpdateUrl, data).toPromise().then(response => {
      console.log(response, 'Assessment Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', message: "Updated Successfully !!" };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to Update Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }


  candidateStatusUpdate(user) {
    const output = 'success';
    return this.http.post(this.getcandidateStatusUpdateUrl, user).toPromise().then(response => {
      console.log(response, 'Status Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      let errData;
      console.log(err.status);
      console.log(err._body);

      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 500) {
        errData = JSON.parse(err._body);
        console.log(err._body);
        const pattfb = new RegExp('TA_APPROVED performed successfully');
        const resfb = pattfb.test(err._body);
        const pattfr = new RegExp('TA_REJECTED performed successfully');
        const resfr = pattfr.test(err._body);

        if (resfb) {
          // alert("TA_APPROVED performed successfully");
          // window.location.href = window.location.origin+'/taProfile?'+'uuid='+user.toId
        } else if (resfr) {
          // alert("TA_REJECTED performed successfully");
          // window.location.href = window.location.origin+'/ta'
        } else {
          return { status: 'error', message: errData.error.message };
        }
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  updateCoachComments(user) {
    const output = 'success';
    return this.http.post(this.getupdateCoachCommentsUrl, user).toPromise().then(response => {
      console.log(response, 'Status Updates');
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      let errData;
      console.log(err.status);
      console.log(err._body);

      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 500) {
        console.log(err._body);
        const pattfb = new RegExp('TA_APPROVED performed successfully');
        const resfb = pattfb.test(err._body);
        const pattfr = new RegExp('TA_REJECTED performed successfully');
        const resfr = pattfr.test(err._body);

        if (resfb) {
          // window.location.href = window.location.origin+'/taProfile?'+'uuid='+user.toId
        } else if (resfr) {
          window.location.href = window.location.origin + '/ta';
        } else {
          return { status: 'error', message: errData.error.message };
        }
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  candidateRegister(user) {
    const output = 'success';
    return this.http.post(this.getCandidateRegisterUrl, user).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { ...baseResponse, status: 'success', message: 'success', data: JSON.parse(this.userData._body) };
      } else if (this.userData.status === 400) {
        return { ...baseResponse, status: 'error', message: 'Failed to register the candidate...!' };
      } else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  candidateUpdate(user) {
    const output = 'success';
    return this.http.post(this.getCandidateUpdateUrl, user).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { ...baseResponse, status: 'success', data: JSON.parse(this.userData._body) };
      } else if (this.userData.status === 400) {
        return { ...baseResponse, status: 'error', message: 'Failed to update the candidate...!' };
      } else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  /**
   * Map the profile pic to the candidate and mark its as the profile pic
   * @param candidateId - userInfoMstrId
   * @param fileId - fileId from the file api
   * @param fileName - file name
   */
  candidateMapProfilePic(candidateId, fileId, fileName) {
    return this.http.post(`${this.postMapProfilePicToCandidateUrl}${candidateId}`, { fileId, fileName }).toPromise().then(resp => {
      if (this.userData.status === 200) {
        return { ...baseResponse, status: 'success', data: resp };
      } else if (this.userData.status === 400) {
        return { ...baseResponse, status: 'error', message: 'Failed to update the candidate...!' };
      } else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(this.handleError);
  }

  getCandidateInfo(id) {
    return this.http.get(this.getCandidateInfoUrl + id + '/').toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*coach*/
  getAllCandidateCoach(data) {
    return this.http.post(this.getAllCoachCandidatesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllCoachesforPgm(id) {
    return this.http.get(this.getAllCoachesforPgmUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  getAllCoachesforCandidate(data) {
    return this.http.get(this.getAllCoachesforCandidateUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCandidate(data) {
    return this.http.post(this.getCandidateUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllCandidate(data) {
    return this.http.post(this.getAllCandidatesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  submitAssignCoachtoCandidate(data) {
    return this.http.post(this.submitAssignCoachCandidateUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }


  getCoachesForAssignedCandidates(data) {
    return this.http.post(this.getAllCoachesForAssignedCandidatesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllCoachesForApplication(location, skills) {
    return this.http.get(this.getAllCoachesForApplicationUrl + location + '/' + skills).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getUnAssignCandidatesForCoach(data) {
    return this.http.post(this.getUnassignedCandidatesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /***  Resume File Upload Function  ***/
  getFileUpload(data) {
    return this.http.post(this.getFileUploadUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /***  Resume File Upload Function  ***/
  getEditResumeUpload(data, id) {
    return this.http.post(this.getEditFileUrl + id, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getFile(id) {
    return this.http.get(this.getFileUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCandidatePrimaryEvaluationReport(mail) {
    return this.http.post(this.getCandidatePrimaryEvaluationReportUrl, mail).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getEmployeePrimaryEvaluationReport(email, course) {
    return this.http.get(this.getEmployeeCourseResult + '/' + email + '/' + course).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getEmployeeMiniAssessmentPrimaryEvaluationReport(email, assessmentId) {
    return this.http.get(this.getEmployeeMiniAssessmentResult + '/' + email + '/' + assessmentId).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }



  updateAssessmentStatus(eventId, status) {
    return this.http.get(this.updateAssessmentStatusUrl + eventId + '/' + status).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllAssessmentforPgm(id) {
    return this.http.get(this.getAllAssessmentforPgmUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /******* ADMIN PORTAL API START HERE  *******/

  /*** Get All Roles  ***/
  getAllRoles() {
    return this.http.get(this.getAllRoleUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllRolePrivilege() {
    return this.http.get(this.getAllRolePrivilegeUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllExperienceLevel() {
    return this.http.get(this.getAllExperienceLevelUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  getAllAssessment() {
    return this.http.get(this.getAllAssessmentUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAssessment() {
    return this.http.get(this.getAllAssessmentDtlsUrl).toPromise().then(response => {
      this.loginData = response;
      return this.loginData._body;
    }).catch(this.handleError);
  }

  /***  GET ALL ACTIVE LOCATION SERVICE  ***/
  getAllLocations() {
    return this.http.get(this.getAllLocationUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /***  GET ALL ACTIVE LOCATION SERVICE  ***/
  getAllSkillTrackMstr() {
    return this.http.get(this.getAllSkillTrackMstrUrl).toPromise().then(response => {

      console.log(response)
      this.loginData = response;

      return JSON.parse(this.loginData._body)

    }).catch(this.handleError)
  }

  /***  GET ALL PGMs - Head_Coaches ***/
  getAllPgMgrs() {
    return this.http.get(this.getAllPgMgrsUrl).toPromise().then(response => {

      console.log(response)
      this.loginData = response;

      return JSON.parse(this.loginData._body)

    }).catch(this.handleError)
  }
  getAllMettlAssessmentDtls() {
    return this.http.get(this.getAllMettlAssessmentDtlsUrl).toPromise().then(response => {
      console.log(response)
      this.loginData = response;
      return JSON.parse(this.loginData._body)
    }).catch(this.handleError)
  }

  getAllLearningPaths() {
    return this.http.get(this.getAllLearningPathsUrl).toPromise().then(response => {
      console.log(response)
      this.loginData = response;
      return JSON.parse(this.loginData._body)
    }).catch(this.handleError)
  }

  getSelectedLearningPath(id) {
    return this.http.get(this.getAllLearningPathsUrl + id).toPromise().then(response => {
      console.log(response)
      this.loginData = response;
      return JSON.parse(this.loginData._body)
    }).catch(this.handleError)
  }

  getAllAssesmentsById(data) {
    return this.http.post(this.getAllAssesmentsByIdUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllSkillTrackMstrAndDtls() {
    return this.http.get(this.getAllSkillTrackMstrAndDtlsUrl).toPromise().then(response => {
      console.log(response)
      this.loginData = response;
      return JSON.parse(this.loginData._body)
    }).catch(this.handleError)
  }

  getAllTechnicalUseCaseList(id) {

    return this.http.get(this.getAllTechnicalUseCaseListUrl + id).toPromise().then(response => {

      console.log(response)
      this.loginData = response;

      return JSON.parse(this.loginData._body)

    }).catch(this.handleError)
  }

  getAllBussniessUseCaseList(id) {

    return this.http.get(this.getAllBussniessUseCaseListUrl + id).toPromise().then(response => {

      console.log(response)
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /***  GET ALL AWS SANDBOX SERVICE  ***/
  getAllAwsDirectoryBundle() {
    return this.http.get(this.getAllAwsDirectoryBundleUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllAwsDirectoryBundleJR(id) {
    return this.http.get(this.getAllAwsDirectoryBundleBySkillUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  // getAllWhiteBoardUc(id){
  //   return this.http.get(this.getAllWhiteBoardUcUrl+id).toPromise().then(response => {
  //     this.loginData = response;
  //     return JSON.parse(this.loginData._body);
  //   }).catch(this.handleError);
  // }

  getAllCodingChallangeUc(id) {
    return this.http.get(this.getAllCodingChallangeUcUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllCaccounts() {
    return this.http.get(this.getAllCaccountsUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getCoachesBySelectedSkills(id) {
    return this.http.get(this.getCoachesBySelectedSkillsUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getInnovationCats() {
    return this.http.get(this.getAllInnovationCatsUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  createInnovationCat(data) {
    return this.http.put(this.addInnovationCatUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  deleteInnovationCats(Id) {
    return this.http.delete(this.delInnovationCatUrl.replace(':categoryId', Id), null)
      .catch((e) => {
        this.handleError(e);
        return e;
      });
  }

  getAllColleges() {
    return this.http.get(this.getAllCollegesUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  addNewCollege(data) {
    return this.http.post(this.getAllCollegesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  updateCollege(data) {
    return this.http.put(this.getAllCollegesUrl + data.id, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  deleteCollege(adminId, collId) {
    return this.http.delete(this.delCollegeUrl.replace(':collegeId', collId).replace(':adminId', adminId), null)
      .catch((e) => {
        this.handleError(e);
        return e;
      });
  }

  getNonActiveColleges() {
    return this.http.get(this.getInactiveCollegesUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  /** ADD Job Requirement  API SERVICE **/
  getaddJobRequirement(data) {
    return this.http.post(this.getaddJobRequirementUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  geteditJobRequirement(data) {
    return this.http.put(this.geteditJobRequirementUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  /***  GET ALL USER SERVICE  ***/
  getAllUsers() {
    return this.http.get(this.getAllUserUrl).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /***  GET ALL USER SERVICE  ***/
  getAllPrivilege(id) {
    return this.http.get(this.getPopulateRoleBasedPrivilegeUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** TRANSFER CANDIDATES **/
  getTransferCandidate(data) {
    return this.http.post(this.getTransferCandidateUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** TRANSFER CANDIDATES **/
  getnominateCoach(data, skills) {
    return this.http.post(this.getnominateCoachUrl + data.userInfoMstrId, skills).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD ROLE API SERVICE **/
  getAddRole(data) {
    return this.http.post(this.getAddRoleUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** EDIT ROLE API SERVICE **/
  getEditRole(data) {
    return this.http.put(this.getEditRoleUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD SKILL API SERVICE **/
  getAddSkill(data) {
    return this.http.post(this.getAddSkillUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD LOCATION API SERVICE **/
  getAddLocation(data) {
    return this.http.post(this.getAddLocationUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD EMPLOYEE API SERVICE **/
  getAddEmployee(data) {
    return this.http.post(this.getAddEmployeeUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD ASSESSMENT DETAILS API SERVICE **/
  getaddAssessmentDetails(data) {
    return this.http.post(this.getaddAssessmentDetailsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD ASSESSMENT DETAILS API SERVICE **/
  getaddAWSDirecBundle(data) {
    return this.http.post(this.getaddAWSDirecBundleUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ADD USER DETAILS API SERVICE **/
  getaddNewUser(data) {
    //data.skillId = [data.skillId];
    return this.http.post(this.getaddNewUserUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** EDIT USER DETAILS API SERVICE **/

  getEditUser(data) {
    //data.skillId = [data.skillId];
    return this.http.put(this.getEditUserUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /**  Tranfer Candidate  API SERVICE **/
  getTranferCandidate(data) {
    return this.http.post(this.getTranferCandidateUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /**  Tranfer Candidate  API SERVICE **/
  adminSearchUser(data) {
    return this.http.post(this.getsearchUserUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /** ASSIGN ROLE TO USER API SERVICE **/
  getassignRoleToUser(data) {
    return this.http.post(this.getassignRoleToUserUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*workspace*/
  describeWorkspaceById(user) {
    const output = 'success';
    return this.http.post(this.describeWorkspaceUrl, user).toPromise().then(response => {
      this.creatWorkspaceData = response;
      if (this.creatWorkspaceData.status === 200) {
        return this.creatWorkspaceData._body;
      } else if (this.creatWorkspaceData.status === 400) {
        return { status: 'error', message: '' };
      } else {
        return { status: 'error', message: 'Something went wrong describeWorkspaceById-workspace.service.ts...!' };
      }
    });
  }

  startWorkspace(Id) {
    const output = 'success';
    return this.http.post(this.startWorkspacesUrl, Id).toPromise().then(response => {
      this.startWorkspaceData = response;
      if (this.startWorkspaceData.status === 200) {
        return this.startWorkspaceData._body;
      } else if (this.startWorkspaceData.status === 400) {
        return { status: 'error', message: 'Invalid credentials...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  /*get use case api*/
  getUsecase(userId, eventId) {
    const url = this.getUsecaseUrl + userId + '/' + eventId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*get use case api*/
  getActiveLocationBy(locationId) {
    const url = this.getActiveLocationByUrl + locationId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*get use case api*/
  getAllSkillTrackDetailsBy(locationId) {
    const url = this.getAllSkillTrackDetailsByUrl + locationId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*get CCindex api*/
  getCCindex(eventId) {
    const url = this.getCCindexUrl + eventId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getDeleteAssessmentId(Id) {
    const url = this.getDeleteAssessmentIdUrl + Id;
    return this.http.delete(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      const errData = JSON.parse(err._body);
      return { status: 'error', message: errData.errorBean.message };
    });
  }
  /* Delete Job Requirment */
  getDeleteJobRequirementId(Id) {
    return this.http.delete(this.deleteJobRequirementUrl.replace(':requirementId', Id), null)
      .catch((e) => {
        this.handleError(e);
        return e;
      });
  }

  getDeleteAwsDirecBundle(Id) {
    const url = this.getDeleteAwsDirecBundleUrl + Id;
    return this.http.delete(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      const errData = JSON.parse(err._body);
      return { status: 'error', message: errData.errorBean.message };
    });
  }

  getDeleteRole(Id) {
    const url = this.getDeleteRoleUrl + Id;
    return this.http.delete(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      const errData = JSON.parse(err._body);
      return { status: 'error', message: errData.errorBean.message };
    });
  }

  getDeleteLocation(Id) {
    const url = this.getDeleteLocationUrl + Id;
    return this.http.delete(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      const errData = JSON.parse(err._body);
      return { status: 'error', message: errData.errorBean.message };
    });
  }

  getDeleteSkillDtls(Id) {
    const url = this.getDeleteSkillDtlsUrl + Id;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      const errData = JSON.parse(err._body);
      return { status: 'error', message: errData.errorBean.message };
    });
  }

  getUpdateAssessmentDetails(data) {
    return this.http.put(this.getUpdateAssessmentDetailsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getUpdateAWSDirecBundle(data) {
    return this.http.put(this.getUpdateAWSDirecBundleUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getUpdateLocation(data) {
    return this.http.put(this.getUpdateLocationUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getUpdateSkillTrackDetails(data) {
    return this.http.post(this.getUpdateSkillTrackDetailsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  setupWorkSpace(data) {
    return this.http.post(this.getSetupWorkSpaceUrl, data).toPromise().then(response => {
      console.log(response, 'getSetupWorkSpaceUrl');
      this.loginData = response;
      const workSpaceData = JSON.parse(this.loginData._body);
      console.log(workSpaceData, 'convert Json workspace Data');
      if (workSpaceData.error) {
        console.log(workSpaceData.error, 'errorMessage');
        return { status: 'error', message: workSpaceData.error.message };
      } else {
        return JSON.parse(this.loginData._body);
      }
    }).catch(this.handleError);
  }

  addMultiUserCourses(data) {
    return this.http.put(this.getaddMultiUserCoursesUrl, data).toPromise().then(response => {
      console.log(response, 'addMultiUserCourses');
      console.log(response['_body'], 'addMultiUserCourses');
      return { status: 'success', message: response['_body'] };
    }).catch(err => {
      console.log(err);
      console.log(err['_body']);
      if (err.status === 400 || err.status === 404) {
        return { status: 'error', message: err['_body'] };
      } else if (err.status === 500) {
        return { status: 'error', message: err['_body'] };
      } else {
        return { status: 'error', message: 'Something went wrong!' };
      }
    });
  }

  addEmployeeEventDetails(data) {
    return this.http.post(this.getaddEmployeeEventDetailsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }


  recommendAssessment(data) {
    return this.http.post(this.getRecommendAssessmentUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  selfAssessment(data) {
    return this.http.post(this.getSelfAssessmentUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      let errData;
      console.log(err.status);
      console.log(err._body);

      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData);
        console.log(errData.error);
        console.log(errData.error.message);
        return { data: null, status: 'error', message: errData.error.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { ...baseResponse, status: 'error', message: errData.error.message };
      } else if (err.status === 502) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        this.router.navigate(['severStop']);
      } else if (err.status === 500) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { ...baseResponse, status: 'error', message: errData.error.message };
      } else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }

    });
  }

  addUserCourses(data) {
    return this.http.post(this.getaddUserCoursesUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      let errData;
      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData);
        console.log(errData.errorBean);
        console.log(errData.errorBean.message);
        return { ...baseResponse, status: 'error', message: errData.errorBean.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { ...baseResponse, status: 'error', message: errData.errorBean.message };
      } else if (err.status === 502) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        this.router.navigate(['severStop']);
      } else if (err.status === 500) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { ...baseResponse, status: 'error', message: errData.errorBean.message };
      } else {
        return { ...baseResponse, status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  assignCoachForEmployee(data) {
    return this.http.post(this.getAssignCoachForEmployeeUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  reportFilter(data) {
    return this.http.post(this.getReportFilterUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  reportEmployeeFilter(data) {
    return this.http.post(this.getEmployeeReportFilterUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  getSubmitForReview(eventId, useCaseId) {
    const reqParem = {};
    return this.http.post(this.getSubmitForRevieUrl + eventId + '/' + useCaseId + '/', reqParem).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  getUserSonarReport(id) {
    return this.http.get(this.getUserSonarReportUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }


  getGITuserDetails(id) {
    return this.http.get(this.getOneGitUserUrl + id).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }


  getCreateGITuser(data) {
    return this.http.post(this.getGITuserDetailsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  getEmployeeCourses(userId) {
    return this.http.get(this.getEmployeeCourseMappingUrl + userId).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  getEmployeeAssessments(userId) {
    return this.http.get(this.getEmployeeAssessmentsUrl + userId).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }
  /* Get Employee Assessment Status */
  getAllEmployeeAssessments(userId) {
    const url = this.getAllEmployeeAssessmentsUrl + userId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllEmployeeAssessmentsNew(userId) {
    const url = this.getAllEmployeeAssessmentsNewUrl + userId + '/';
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }
  /* Get Employee Assessment Status */
  getEmployeeAssessmentStatus(userInfoMstrId) {
    const url = this.getEmployeeAssessmentStatusUrl + userInfoMstrId;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /* Get Employee course  */
  getEmployeeAllCourse(uid) {
    const url = this.getEmployeeCourseUrl + uid;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  getAllEmployeesForCoach(data) {
    const url = this.getAllEmployeesForCoachUrl + data;
    return this.http.get(url).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  /*coach employee*/
  employeeStatusUpdate(user) {
    const output = 'success';
    const url = this.getEmployeeStatusUpdateUrl + user.userInfoMstrId + '/' + user.courseId + '/' + user.status;
    return this.http.get(url).toPromise().then(response => {
      this.userData = response;
      if (this.userData.status === 200) {
        return { status: 'success', data: this.userData._body };
      } else if (this.userData.status === 400) {
        return { status: 'error', message: 'Failed to save Details...!' };
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    }).catch(err => {
      let errData;
      console.log(err.status);
      console.log(err._body);
      if (err.status === 400) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 403) {
        errData = JSON.parse(err._body);
        console.log(errData.error);
        return { status: 'error', message: errData.error.message };
      } else if (err.status === 500) {
        errData = JSON.parse(err._body);
        console.log(err._body);
      } else {
        return { status: 'error', message: 'Something went wrong...!' };
      }
    });
  }

  // getAllEmployeesForCoach(data) {
  //   const url = this.getAllEmployeesForCoachUrl + data;
  //   return this.http.get(url).toPromise().then(response => {
  //     this.loginData = response;
  //     return JSON.parse(this.loginData._body);
  //   }).catch(this.handleError);
  // }

  /*coach employee*/
  updateAwsWorkspaceStatus(adId: string, status: string) {
    return this.http.post(this.updateAwsWorkspaceStatusUrl.replace(':adId', adId).replace(':status', status), null)
      .catch((e) => {
        this.handleError(e);
        return e;
      });
  }

  terminateAwsWorkspaceStatus(data) {
    return this.http.post(this.getTerminateAwsWorkspaceUrl, data).toPromise().then(response => {
      return response;
    }).catch(err => {
      this.handleError(err);
    });
  }

  candidateReschedule(id) {
    return this.http.get(this.candidateRescheduleUrl + id).toPromise();
  }

  createLearingPath(data) {
    const output = 'success';
    return this.http.post(this.getAllLearningPathsUrl, data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(this.handleError);
  }

  editLearningPath(data) {

    return this.http.put(this.getAllLearningPathsUrl, data).toPromise().then(response => {
      console.log(response, 'Edited Learning Path');
      console.log(response['_body'], 'Edited Learning Path Body');
      return { status: 'success', message: response['_body'] };
    }).catch(err => {
      console.log(err);
      console.log(err['_body']);
      if (err.status === 400 || err.status === 404) {
        return { status: 'error', message: err['_body'] };
      } else if (err.status === 500) {
        return { status: 'error', message: err['_body'] };
      } else {
        return { status: 'error', message: 'Something went wrong!' };
      }
    });
  }

  getCourseByCourseIds(data) {
    return this.http.get(this.getCourseByCourseIdsUrl + data).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  deleteLearningPath(learningPathId: any, userInfoMstrId: any) {
    return this.http.delete(this.deleteLearningPathUrl.replace(':learningPathId', learningPathId).replace(':userInfoMstrId', userInfoMstrId), null)
      .catch((e) => {
        this.handleError(e);
        return e;
      });
  }

  getAllReviewDetails() {
    return this.http.get(this.getReviewDetails).toPromise().then(response => {
      return response;
    }).catch(err => {
      this.handleError(err);
      return err;
    });
  }

  getReviewerDetails(eventDtlsId: string) {
    return this.http.get(this.getReviewerDetailsUrl.replace(':eventDtlsId', eventDtlsId)).toPromise().then(response => {
      this.loginData = response;
      return JSON.parse(this.loginData._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  /**
   * New API for unified login/signUp
   * Verify email ID to check status of a user for redirecting to particular screen
   */

  getStatusVerifyEmailId(emailId) {
    console.log('coming in the service');
    return this.http.get(this.verifyEmailId + emailId).toPromise().then((response: any) => {
      console.log(response);
      return JSON.parse(response._body);
    }).catch(err => {
      this.handleError(err);
    });
  }

  /**
   * New API for signup for candidates.
   * API to be called for users whose mail ID already exsists in the system.
   * Need to set only password
   */
  registerCandidateWithOnlyPassword(regObj) {
    return this.http.post(this.registerCandidateUrl, regObj).toPromise().then((response: any) => {
      console.log(response);
      return JSON.parse(response._body);
    }).catch(err => {
     var errData = JSON.parse(err._body);
     errData.error.status = 'error';
     return errData.error;
    });
  }

  /**
   *  New API for student registration
   * Unified Signup
   */
  studentUnifiedSignUp(userData) {
    const output = 'success';
    return this.http.post(this.registerStudentUrl, userData).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  getFeedbackReport(data) {
    return this.http.post(this.getFeedbackReportUrl, data).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  getFeedbackReportdowmloading(data) {
   let requestURL = '';
    if(data.location == undefined || data.location.length == 0) {
    //  data.location = null;
       requestURL = this.getFeedbackReportDownloadingUrl + '?' + 'position=' + data.position +  '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
    
    }else {
       requestURL = this.getFeedbackReportDownloadingUrl + '?' + 'position=' + data.position + '&location=' + data.location + '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
    
    }
  //  let requestURL = this.getFeedbackReportDownloadingUrl + '?' + 'position=' + data.position + '&location=' + data.location + '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
    
    window.open(requestURL);
    return this.http.get(requestURL).toPromise().then(response => {
     // this.signupData = response;
      return response; //JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  getCandidateCheckedInReportData(data) {
    return this.http.post(this.getCandidateCheckedInReport, data).toPromise().then(response => {
      this.signupData = response;
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }

  getCandidateCheckedInReportDownloading(data) {
    let requestURL = '';
    if(data.location == undefined || data.location.length == 0) {
     // data.location = null;
     console.log('coming in if');
       requestURL = this.getCandidatecheckinDownloadingUrl + '?' + 'position=' + data.position + '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
   
    }else {
      console.log('coming in else');
      console.log(data.location);
       requestURL = this.getCandidatecheckinDownloadingUrl + '?' + 'position=' + data.position + '&location=' + data.location + '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
   
    }
  //  let requestURL = this.getCandidatecheckinDownloadingUrl + '?' + 'position=' + data.position + '&location=' + data.location + '&fromDate=' + data.fromDate + '&toDate=' + data.toDate;
    window.open(requestURL);
    return this.http.get(requestURL, data).toPromise().then(response => {
      this.signupData = response;
      console.log(response);
      return JSON.parse(this.signupData._body);
    }).catch(this.handleError);
  }
}
