import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
import Urls from './employee-urls';
import { EmployeeDetailsResponse, StatusCount, ApplyForCoachResponse } from 'app/models/employee.model';
import { File } from 'app/models/InnovationIdea.model';

@Injectable()
export class EmployeeHttpService {
  header;
  constructor(private http: HttpClient) { }

  /**
   * Get employee details
   *
   * @param {number} employeeId
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getEmployeeDetails(employeeId: number): Observable<EmployeeDetailsResponse> {
    if (!employeeId && employeeId !== 0) {
      return Observable.throw('Could not fetch employee data with undefined id');
    }
    return this.http.get<EmployeeDetailsResponse>(Urls.getEmployeeDetails.replace(':userId', employeeId.toString()));
  }

  /**
   * Get employee list details
   *
   * @param {number[]} employeeIdList
   * @returns {Observable<any>}
   * @memberof CapabilityTransformationHttpService
   */
  public getListEmployeeDetails(employeeIdList: number[]): Observable<any> {
    return this.http.get<any>(Urls.getListEmployeeDetails.replace(':employeeIdList', employeeIdList.toString()));
  }

  /**
   * Get employee details
   *
   * @param {string} employeeId
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public updateFirstTimeLoginStatus(employeeId: string): Observable<any> {
    return this.http.get<any>(Urls.updateFirstTimeLoginStatus.replace(':userId', employeeId));
  }

  /**
   * Upload a file
   *
   * @param {FormData} formData
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public uploadEmployeeRelatedFile(formData: FormData): Observable<any> {
    return this.http.post(Urls.uploadFile, formData);
  }

  /**
   * Get file contents
   *
   * @param {number} fileId
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getEmployeeRelatedFile(fileId: number = -1): Observable<File[]> {
    return this.http.get<File[]>(Urls.getFileContents.replace(':fileId', fileId.toString()));
  }


  public updateSkillForEmployee(employeeEmailId: string, skillIdList: Array<number>): Observable<string> {

    return this.http.put(
      Urls.updateSkillForEmployee,
      { skillId: skillIdList, email: employeeEmailId },
      { responseType: 'text' });
  }

  /**
   * Get Course Categories
   *
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getCourseCategories(): Observable<EmployeeDetailsResponse> {
    return this.http.get<EmployeeDetailsResponse>(Urls.getCourseCategories);
  }

  /**
   * Get Courses by Category
   *
   * @param {string} categoryName
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getCourseByCategory(categoryName: string): Observable<EmployeeDetailsResponse> {
    return this.http.get<EmployeeDetailsResponse>(Urls.getCourseByCategory.replace(':categoryName', categoryName));
  }

  /**
   * Get Categories By Skills
   *
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getActiveCoursesCategoriesBySkills(): Observable<EmployeeDetailsResponse> {
    return this.http.get<EmployeeDetailsResponse>(Urls.getActiveCoursesCategoriesBySkills);
  }

  /**
 * Post Employee courses
 *
 * @param {number} employeeId
 * @param {*} course
 * @returns {Observable<any>}
 * @memberof EmployeeHttpService
 */
  public addUserCourses(course: any): Observable<any> {
    return this.http.post(Urls.addUserCourses, course);
  }

  /**
   * Post Employee courses
   *
   * @param {number} employeeId
   * @param {*} course
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public searchEmployee(filterParam: any): Observable<any> {
    return this.http.post(Urls.getSearchEmployee.replace(':filterParam', filterParam.toString()), filterParam);
  }

  /**
   * Post Employee courses
   *
   * @param {number} employeeId
   * @param {*} course
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public quicksearchEmployee(filterParam: any): Observable<any> {
    return this.http.post(Urls.quickSearchEmployee.replace(':filterParam', filterParam.toString()), filterParam);
  }

  /**
   * Get Dashboard Courses
   *
   * @param {number} employeeId
   * @returns {Observable<any>}
   * @memberof EmployeeHttpService
   */
  public getUserCoursesDashboard(employeeId: number): Observable<any> {
    return this.http.get<any>(Urls.getUserCoursesDashboard.replace(':employeeId', employeeId.toString()));
  }

  /**
  * Get User Courses Count By Status
  *
  * @param {number} employeeId
  * @returns {Observable<StatusCount>}
  * @memberof EmployeeHttpService
  */
  public getUserCoursesCountByStatus(employeeId: number): Observable<StatusCount> {
    return this.http.get<StatusCount>(Urls.getUserCoursesCountByStatus.replace(':employeeId', employeeId.toString()));
  }

  public getCourseBySkillId(skillId: number): Observable<any> {
    return this.http.get<any>(Urls.getCourseBySkillId.replace(':skillId', skillId.toString()));
  }

  public addMultiUserCourses(course: any): Observable<any> {
    return this.http.post(Urls.addMultiUserCourses, course);
  }

  public addProjectDtlsForEmployee(req: {
    projectDtlsId?: number,
    description: string,
    skills: Array<number>,
    title: string,
    userInfoMstrId: number
  }): Observable<EmployeeDetailsResponse> {
    return this.http.post<EmployeeDetailsResponse>(Urls.addProjectDtlsForEmployee, req);
  }

  public applyForCoach(userInfoMstrId: string): Observable<ApplyForCoachResponse> {
    return this.http.get<ApplyForCoachResponse>(Urls.applyForCoach.replace(':userInfoMstrId', userInfoMstrId));
  }

  public updateEmployeeDetails(employeeDetails: {
    email: string,
    firstName: string,
    lastName: string,
    locationId: number,
    phone: number,
    privilegeId: number,
    skillId: number[]
  }): Observable<EmployeeDetailsResponse> {
    return this.http.put<EmployeeDetailsResponse>(Urls.updateEmployeeDetails, employeeDetails);
  }

  public uploadProfile(userId: number, req: { fileId: number, fileName: string }): Observable<{
    uploadStatus: string,
    errorBean: any
  }> {
    return this.http.post<any>(Urls.uploadProfileUrl.replace(':userId', userId.toString()), req);
  }

  // get course details for BNY employee
  public getBNYEmployeeCourseDetails(couseSelection: string): Observable<any> {
    return this.http.get(Urls.bnyCourseDetails.replace('couseSelection', couseSelection));
  }
  // submit selected assessment
  public submitSelectedAssessment(selectedAssessment: any): Observable<any> {
    return this.http.post(Urls.subAssessmentDetails, selectedAssessment);
  }
  // submit selected course
  public submitSelectedCourse(selectedCourses: any): Observable<any> {
    return this.http.post(Urls.subCourseDetails, selectedCourses);
  }
  // get reviewer details
  public getEmployeeReviewDetails(reviewerId: string, status: string): Observable<any> {
    return this.http.get(
      Urls.getReviewDetails
        .replace('reviewerId', reviewerId)
        .replace('status', 'PENDING,PASSED,REJECTED,DONE')
    );
  }
  // get reviewer detailsList
  public getEmployeeReviewDetailsList(reviewerId: string, status: string): Observable<any> {
    return this.http.get(
      Urls.getReviewDetailsList
        .replace('reviewerId', reviewerId)
        .replace('status', status)
    );
  }
  // get employee Image
  public getEmployeeImage(userId: string): Observable<any> {
    return this.http.get(Urls.getImageDetails.replace('reviewerId', userId));
  }
  // get employee git Details
  public getEmployeeGitDetails(emailId: string): Observable<any> {
    return this.http.get(Urls.getGitDetails.replace('emailId', emailId));
  }
  // update employee review Status
  public updateEmployeeReviewStatus(eventDetailsId: string, userId: string, status: string): Observable<any> {
    return this.http.put(
      Urls.updateEmployeeReviewStatus
        .replace('eventDetailsId', eventDetailsId)
        .replace('userId', userId)
        .replace('status', status)
      , null);
  }

  // get reviewFeedBackQuestions
  public getReviewFeedBackQuestions(useCaseId: string): Observable<any> {
    return this.http.get(Urls.getReviewQuestions.replace('useCaseId', useCaseId));
  }

  // submit Employee FeedBack
  public submitEmployeeFeedBack(feedback): Observable<any> {
    return this.http.post(Urls.subEmployeeFeedback, feedback);
  }

  // get employee code Review Details
  public getEmployeeCodeReviewDetails(eventDtlsId: string): Observable<any> {
    return this.http.get(Urls.getCodeReviewDetails.replace('eventDtlsId', eventDtlsId));
  }

  // get employee Review Score
  public getEmployeeReviewScore(eventDtlsId: string, reviewerId: string): Observable<any> {
    return this.http.get(
      Urls.getEmployeeReviewScore
        .replace(':eventDtlsId', eventDtlsId)
        .replace(':reviewerId', reviewerId)
    );
  }

  // get learning path card details
  public getLearningPathCardDetails(learningPathId: string): Observable<any> {
    return this.http.get(Urls.learningPathCourseDetails.replace('id', learningPathId));
  }

  // get the course releted to learning path
  public getLearningPathCourseDetails(courseId: string): Observable<any> {
    return this.http.get(Urls.bnyCourseCardDetails.replace('courseId', courseId));
  }

  // get the assessment releted to learning path
  public getLearningPathAssessmentDetails(assessmentIdCollection): Observable<any> {
    return this.http.post(Urls.bnyAssessmentCardDetails, assessmentIdCollection);
  }
  /* Get all learning Path  of employee in dashboard*/
  // get the assessment releted to learning path
  public getLearningPathOfEmp(userInfoMstrId): Observable<any> {
    return this.http.get(Urls.getEmployeeLearningPath.replace('userInfoMstrId', userInfoMstrId));
  }

  // Get All Repo details
  public getAllTechStacks(): Observable<any> {
     return this.http.get(Urls.getAllTechStacks);
  }

  // Create Project
  public createProject(projectDetails): Observable<any> {
    return this.http.post(Urls.createGitLabProject, projectDetails);
  }

  public getAllProjectsByUser(emailId): Observable<any> {
    return this.http.get(Urls.getAllProjectByUser.replace('emailId', emailId));

  }

  public getAllProjects(): Observable<any> {
    return this.http.get(Urls.getAllProject);

  }
  public getAllRequestedProjects(): Observable<any> {
    this.header = new HttpHeaders().set('Content-Type', 'application/json');
    return this.http.get(Urls.getBitbucketAllRequestedProject, {headers: this.header});

  }

  public getAllCreatedProjects(): Observable<any> {
    this.header = new HttpHeaders().set('Content-Type', 'application/json');
    return this.http.get(Urls.getBitbucketAllCreatedProject, {headers: this.header});

  }

  public updateProjectDetails(projectDetails): Observable<any> {
    return this.http.post(Urls.updateBitbucketProject, projectDetails);
  }

  public getProjectById(projectId): Observable<any> {
    return this.http.get(Urls.getProjectById.replace('projectID', projectId));
  }

  public getCoachDetails(coachId): Observable<any> {
    return this.http.get(Urls.getCoachDetails.replace('coachId', coachId));
  }

  public getAllEmployees(): Observable<any> {
    return this.http.get(Urls.getAllEmployees);
  }

  public getGitUserDetail(emailID): Observable<any> {
    return this.http.get(Urls.getGitUserDetail.replace('emailID', emailID));
  }
}
