import { Injectable } from '@angular/core';
import { ConfigService } from '../../config/config.service';
import { FleioApiService } from '../fleio-api.service';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IBaseFleioObjectModel } from '../base-model/base-fleio-object.model';
import { IActiveTosResponseModel } from '@fleio-api/core/model/active-tos-response.model';

@Injectable({
  providedIn: 'root'
})
export class TosAgreementsApiService extends FleioApiService<IBaseFleioObjectModel> {
  constructor(protected httpClient: HttpClient, protected config: ConfigService) {
    super();
    this.setEndpoint(config.getPanelApiUrl('tos-agreements'));
  }

  getActiveTOS(): Observable<IActiveTosResponseModel> {
    return this.getAction('get_active_tos');
  }

  agree(tosId): Observable<any> {
    return this.objectPostAction(tosId, 'agree', {});
  }

  getTos(tosId): Observable<IActiveTosResponseModel> {
    return this.getAction('', {
      id: tosId
    });
  }

}
