package com.baoshi.swms.net.subscribe;

import android.util.Base64;

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.observers.DisposableObserver;
import okhttp3.ResponseBody;

/**
 * WAS API请求订阅器
 *
 * @author Zhendong Zhou
 * @date   2021/12/3 15:53
 */
public class WasSubscribe {
    public static void login(String username, String pwd, DisposableObserver<ResponseBody> subscriber) {
        pwd = Base64.encodeToString(pwd.getBytes(),Base64.DEFAULT);//base64加密
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().login(username,pwd);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void recover(String batch, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().recover(batch);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void dailyBilling(String deliverAt, double fee, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().dailyBilling(deliverAt, fee);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void dispatch(Map<String,String> map, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().dispatch(map);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void getDispatchList(String searchTxt, String deliverAt, Integer page, Integer paginate, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().getDispatchList(searchTxt,deliverAt,page,paginate);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void getStocktaking(String stocktakingId, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().getStocktaking(stocktakingId);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void getLocStocktakingRatio(Long stocktakingId, String location, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().getLocStocktakingRatio(stocktakingId,location);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void getLocGoodsInfo(Long stocktakingId, String location, String barcode, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().getLocGoodsInfo(stocktakingId,location, barcode);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }

    public static void stocktaking(Map<String,Object> map, DisposableObserver<ResponseBody> subscriber){
        Observable<ResponseBody> observable = WasBaseSubscribe.getOkHttpApi().stocktaking(map);
        WasBaseSubscribe.toSubscribe(observable, subscriber);
    }
}
