import { Component } from '@angular/core';
import { DetailsComponentBase } from '@objects-view/details-component-base';
import { IPeriodicTaskLogModel } from '@fleio-api/logger/model/periodic-task-log.model';
import { ConfigService } from '@shared/config/config.service';

@Component({
  selector: 'app-periodic-task-log-details-overview',
  templateUrl: './periodic-task-log-details-overview.component.html',
  styleUrls: ['./periodic-task-log-details-overview.component.scss']
})
export class PeriodicTaskLogDetailsOverviewComponent extends DetailsComponentBase<IPeriodicTaskLogModel> {
  constructor(public config: ConfigService) {
    super();
  }

  downloadLogFile() {
    this.config.authService.generateOtpToken().subscribe(token => {
      const downloadUrl = this.config.getPanelApiUrl(
        `logger/periodic-task-log/${this.object.id}/download_log?fleio-token=${token}`
      );
      window.location.href = downloadUrl;
    });
  }
}
