import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import Urls from './capability-transformation-urls';
import {
  CapabilityTransformationCourseList,
  UserCourseMapping,
  CourseList,
  CourseUpdatePayload,
  Course
} from 'app/models/capability-transformation/course-list.model';

@Injectable()
export class CapabilityTransformationHttpService {

  constructor(private http: HttpClient) { }

  /**
   * Get course by Id
   *
   * @param {number} courseId
   * @returns {Observable<CapabilityTransformationCourseList>}
   * @memberof CapabilityTransformationHttpService
   */
  public getCourseByCourseId(courseId: number): Observable<any> {
    return this.http.get<any>(Urls.getCourseByCourseId.replace(':courseId', courseId.toString()));
  }

  /**
   * Get All tab dashboard Courses
   *
   * @param {number} employeeId
   * @returns {Observable<CapabilityTransformationCourseList>}
   * @memberof CapabilityTransformationHttpService
   */
  public getUserCoursesDashboard(employeeId: number): Observable<CapabilityTransformationCourseList> {
    return this.http.get<CapabilityTransformationCourseList>(Urls.getUserCoursesDashboard.replace(':employeeId', employeeId.toString()));
  }

  /**
   * Returns a list of courses filtered by category and skill
   *
   * @param {*} data
   * @returns {Observable<any>}
   * @memberof CapabilityTransformationHttpService
   */
  public getCourseByCategoryAndSkill(data): Observable<any> {
    return this.http.post<any>(Urls.getCourseByCategoryAndSkill, data);
  }

  /**
   * Update courses status
   *
   * @param {CourseUpdatePayload} course
   * @returns {Observable<any>}
   * @memberof CapabilityTransformationHttpService
   */
  public updateUserCourses(course: CourseUpdatePayload[]): Observable<any> {
    return this.http.put<CourseUpdatePayload>(Urls.updateUserCourses, course);
  }
}
