import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import {
  Http,
  Headers,
  RequestOptions,
} from '@angular/http';
import { CryptoService } from '../crypto/crypto.service';

@Injectable({
  providedIn: 'root',
})
export class SearchserviceService {
  baseurl = environment.baseurl;
  constructor(public http: Http, private crypto: CryptoService) { }

  async getSearchData(token) {
    return new Promise((resolve) => {
      var certi_id = localStorage.getItem('CisspCourseId');
      var data = {
        data: this.crypto.encrypt(JSON.stringify({
          certi_id: certi_id
        }))
      }
      let headers = new Headers();
      headers.append('Accept', 'application/json');
      headers.append('Authorization', 'Bearer ' + token);
      let options = new RequestOptions({ headers: headers });
      var url = this.baseurl + environment.VIDEO_SEARCH;
      this.http.post(url, data, options).subscribe(
        (res) => {
          resolve([{ status: res.status, json: res['_body'] }]);
        },
        (err) => {
          resolve([{ status: err.status, json: err['_body'] }]);
        }
      );
    });
  }
}
