import {Injectable} from '@angular/core';
import {RewardExModel} from '../models/reward-ex.model';
import {Observable} from 'rxjs';
import {HttpClient} from '@angular/common/http';
import {AppConfig} from '../app.config';
import {DataStateChangeEvent} from '@progress/kendo-angular-grid';
import {RewardExListResultModel} from '../models/reward-ex-list-result.model';
import {State} from '@progress/kendo-data-query';

@Injectable({providedIn: 'root'})
export class RewardService {
  constructor(private http: HttpClient, private cfg: AppConfig) {
  }

  public getRewardExListByPayoutId(payOutId: number): Observable<RewardExListResultModel>{
    const state = {
      skip: 0, take: 0, filter: {
        logic: 'and',
        filters: [
          {field: 'PayOutId', operator: 'eq', value: payOutId}
        ]
      }
    };
    return this.getRewardExList(state as State);
  }

  public getUserReward(userid?: string): Observable<RewardExModel[]>{
    if (! userid ) { userid = ''; }
    return this.http.get<RewardExModel[]>(this.cfg.getUrl('user-reward/' + userid));
  }

  public getRewardExList(state: State): Observable<RewardExListResultModel> {
    return this.http.post<RewardExListResultModel>(this.cfg.getUrl('reward-ex-list/'), state);
  }
}
