import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import Urls from './assessment-urls';
import { EmployeeCourseAssessmentResponse, EmployeeCourseAssessmentPayload } from 'app/models/assessment/employee-assessment.model';
import { CANDIDATE_STATUS_NAMES } from 'app/models/candidateStatus';
import {EmployeeMiniAssessmentResponse} from "../../models/assessment/employee-assessment.model";

@Injectable()
export class AssessmentHttpService {

  constructor(private http: HttpClient) { }

    /**
     * Get the course assessment for an employee
     *
     * @param {number} employeeId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public getEmployeeCourseAssessment(employeeId: number, courseId: number): Observable<EmployeeCourseAssessmentResponse> {
      return this.http.get<EmployeeCourseAssessmentResponse>(Urls.getEmployeeCourseAssessment.replace(':employeeId', employeeId.toString()).replace(':courseId', courseId.toString()));
    }

    /**
     * Get the mini assessment for an employee
     *
     * @param {number} employeeId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public getEmployeeMiniAssessment(employeeId: number, assessmentId: number): Observable<EmployeeMiniAssessmentResponse> {
      return this.http.get<EmployeeMiniAssessmentResponse>(Urls.getEmployeeMiniAssessment.replace(':employeeId', employeeId.toString()).replace(':assessmentId', assessmentId.toString()));
    }

    /**
     * Creates a new event for a course assessment
     *
     * @param {EmployeeCourseAssessmentPayload} data
     * @returns {Observable<any>}
     * @memberof AssessmentHttpService
     */
    public create(data: EmployeeCourseAssessmentPayload[]): Observable<any> {
      return this.http.post<any>(Urls.addEventDetails, { courseDetails: data });
    }

    /**
     * Creates a new event for a course assessment
     *
     * @param {*} data
     * @returns {Observable<any>}
     * @memberof AssessmentHttpService
     */
    public updateStatus(data): Observable<any> {
      return this.http.post<any>(Urls.updateStatus, data);
    }

    /**
     * Get usecase
     *
     * @param {number} employeeId
     * @param {number} eventId
     * @param {number} courseId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public getUsecase(employeeId: number, eventId: number, courseId: number): Observable<any> {
      return this.http.get<any>(Urls.getUsecase.replace(':employeeId', employeeId.toString()).replace(':eventId', eventId.toString()).replace(':courseId', courseId.toString()));
    }

    /**
     * Get Mini Assessment usecase
     *
     * @param {number} employeeId
     * @param {number} eventId
     * @param {number} AssessmentId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public getMiniAssessmentUsecase(employeeId: number, eventId: number, assessmentId: number): Observable<any> {
      return this.http.get<any>(Urls.getMiniAssessmentUsecase.replace(':employeeId', employeeId.toString()).replace(':eventId', eventId.toString()).replace(':courseId', assessmentId.toString()));
    }

    /**
     * Update course assessment status
     *
     * @param {number} employeeId
     * @param {number} eventId
     * @param {number} courseId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public updateCourseStatus(employeeId: number, courseId: number, status: CANDIDATE_STATUS_NAMES): Observable<any> {
      return this.http.get<any>(Urls.updateCourseStatus.replace(':employeeId', employeeId.toString()).replace(':courseId', courseId.toString()).replace(':status', status));
    }

    /**
     * Update Mini assessment status
     *
     * @param {number} employeeId
     * @param {number} eventId
     * @param {number} AssessmentId
     * @returns {Observable<EmployeeCourseAssessment>}
     * @memberof AssessmentHttpService
     */
    public updateAssessmentStatus(employeeId: number, assessmentId: number, status: CANDIDATE_STATUS_NAMES): Observable<any> {
      return this.http.get<any>(Urls.updateAssessmentStatus.replace(':employeeId', employeeId.toString()).replace(':assessmentId', assessmentId.toString()).replace(':status', status));
    }
}
