import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {AuthService} from './auth.service';
import {Observable} from 'rxjs';
import {PayOutExModel} from '../models/payout.ex.model';
import {CompositeFilterDescriptor} from '@progress/kendo-data-query';
import {PayoutModel} from '../models/payout.model';

@Injectable({providedIn: 'root'})
export class PayOutService {
  constructor(private http: HttpClient, private auth: AuthService ){ }

  public getPayOutEx(id: number): Observable<PayOutExModel> {
    return this.http.get<PayOutExModel>(this.auth.getUrl('payout-ex/' + id));
  }

  public getPayOutList(filter: CompositeFilterDescriptor): Observable<PayOutExModel[]> {
    return this.http.post<PayOutExModel[]>(this.auth.getUrl('payout-ex-list/'), filter);
  }

  public savePayOut(po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout/'), po);
  }

  public setPayOutPrepared(po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-prepared/'), po);
  }

  public setPayOutUnPrepared( po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-unprepared/'), po);
  }

  public setPayOutApproved(po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-approved/' ), po);
  }

  public setPayOutUnapproved(po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-unapproved/'), po);
  }

  public setPayOutPaid( po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-paid/' ), po);
  }

  public setPayOutUnpaid(po: PayoutModel): Observable<PayOutExModel>{
    return this.http.post<PayOutExModel>(this.auth.getUrl('payout-unpaid/'), po);
  }
}
