import { Injectable } from '@angular/core';
import { ConfigService } from '../../config/config.service';
import { FleioApiService } from '../fleio-api.service';
import { HttpClient } from '@angular/common/http';
import { IPeriodicTaskLogModel } from '@fleio-api/logger/model/periodic-task-log.model';
import { FleioId } from '@fleio-api/base-model/base-fleio-object.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class PeriodicTaskLogApiService extends FleioApiService<IPeriodicTaskLogModel> {
  // noinspection JSUnusedGlobalSymbols
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('logger/periodic-task-log'));
  }

  getLog(periodicTaskId: FleioId): Observable<string> {
    return this.objectGetAction(periodicTaskId, 'get_log').pipe(map(response => response.log));
  }
}
