package com.ifavine.pay.api;


import android.text.TextUtils;

import com.ifavine.pay.vo.CanteenWindow;
import com.ifavine.pay.vo.CommonListResponse;

import com.ifavine.pay.vo.CommonResponse;
import com.ifavine.pay.vo.LocalRecordReport;
import com.ifavine.pay.vo.MonthRecordReport;
import com.ifavine.pay.vo.User;
import com.ifavine.pay.vo.WindowCostAmount;

import org.json.JSONObject;

import okhttp3.RequestBody;
import retrofit2.Call;

/**
 * Created by tree on 7/13/2016.
 */
public class APIWrapper extends RetrofitUtil {
    private static APIWrapper mAPIWrapper;

    public static APIWrapper getInstance() {
        if (mAPIWrapper == null) mAPIWrapper = new APIWrapper();
        return mAPIWrapper;
    }

    /**
     * 日事日毕列表
     *
     * @param Page
     * @param PageSize
     * @return
     */

    public Call<CommonResponse<User>> getMsgDaliyList(int Page, int PageSize) {

        JSONObject data = new JSONObject();
        try {
            data.put("Page", Page);
            data.put("PageSize", PageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return getAPIService().getMsgDaliyList(data.toString());
    }

    /**
     * * 日事日毕列表
     * status :0待处理 1处理中 2待评价 3未关闭 4关闭
     * DutyStatus ： 1、已认领 2、可认领 3、需指定
     * Satisfied =0或null未操作 =1满意 =2不满意(正式机)
     *
     * @param Page
     * @param PageSize
     * @param Status
     * @param KeyWord
     * @param Sno
     * @param CreatorID
     * @param Title
     * @param StartTime
     * @param EndTime
     * @return
     */
    public Call<CommonListResponse<User>> getMsgDaliyList2(int Page, int PageSize, int Status, String KeyWord, String Sno, String CreatorID, String Title, String StartTime, String EndTime) {

        JSONObject data = new JSONObject();
        try {
            data.put("Page", Page);
            data.put("PageSize", PageSize);
            data.put("Status", Status);
            data.put("KeyWord", KeyWord);
            data.put("Sno", Sno);
            data.put("CreatorID", CreatorID);
            data.put("Title", Title);
            data.put("StartTime", StartTime);
            data.put("EndTime", EndTime);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return getAPIService().getMsgDaliyList2(data.toString());
    }

    /**
     * 服务器时间
     *
     * @return
     */
    public Call<CommonResponse<String>> getServerDate() {
        String obj = "";
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj);
        return getAPIService().GetServerDate(body);
    }

    public Call<CommonResponse<String>> SubmitPaying(String PayCode, String Mac, String DeviceNo) {
        JSONObject data = new JSONObject();
        try {
            data.put("PayCode", PayCode);
            data.put("Mac", Mac);
            data.put("DeviceNo", DeviceNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), data.toString());
        return getAPIService().SubmitPaying(body);
    }

    /**
     * @param CanteenName
     * @param WindowName
     * @param sDate
     * @param eDate
     * @param dinnerType
     * @param PageIndex
     * @param PageSize
     * @return
     */
    public Call<CommonListResponse<LocalRecordReport>> GetLocalRecordReport(String CanteenName, String WindowName,
                                                                            String sDate, String eDate,
                                                                            String dinnerType, String record, String PageIndex,
                                                                            String PageSize) {
        // "CanteenName": "第二食堂",
        // "WindowName": "7号",
        // "sDate": "2018-02-10 16:14:54.000",
        // "eDate": "2018-10-18 16:14:54.000",
        // "dinnerType": "2",
        // "PageIndex":"2",
        // "PageSize":"3"
        JSONObject obj = new JSONObject();
        try {
            obj.put("CanteenName", CanteenName);
            obj.put("WindowName", WindowName);
            obj.put("sDate", sDate);
            obj.put("eDate", eDate);
            if (!TextUtils.isEmpty(dinnerType)) {
                obj.put("dinnerType", dinnerType);
            }
            if (!TextUtils.isEmpty(record)) {
                obj.put("record", record);
            }
            obj.put("PageIndex", PageIndex);
            obj.put("PageSize", PageSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().GetLocalRecordReport(body);
    }

    /**
     * @param WinName
     * @param CanteenNo
     * @param sDate
     * @param eDate
     * @param dinnerType
     * @param PageIndex
     * @param PageSize
     * @param record
     * @return
     */
    public Call<CommonResponse<String>> GetConsumRecordReport(String WinName, String CanteenNo,
                                                              String sDate, String eDate,
                                                              String dinnerType, String PageIndex,
                                                              String PageSize, String record) {
        // WinName": "7号",//可填或不填，窗口号
        // "CanteenNo": "001",
        // "sDate": "2018-02-06 15:06:56.000",
        // "eDate": "2018-10-18 15:06:56.000",
        // "dinnerType": "3",//可填或不填，用餐类型
        // "record": "1",//可填或不填，1：正常记录2：异常记录
        // "PageIndex": "2",
        // "PageSize": "10"
        JSONObject obj = new JSONObject();
        try {
            obj.put("WinName", WinName);
            obj.put("CanteenNo", CanteenNo);
            obj.put("sDate", sDate);
            obj.put("eDate", eDate);
            obj.put("dinnerType", dinnerType);
            obj.put("PageIndex", PageIndex);
            obj.put("PageSize", PageSize);
            obj.put("record", record);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().GetConsumRecordReport(body);
    }


    /**
     * 月消费记录
     *
     * @return
     */
    public Call<CommonListResponse<MonthRecordReport>> GetMonthRecordReport(String Year, String Month) {
        // "CanteenName": "第二食堂",
        // "WindowName": "7号",
        // "sDate": "2018-02-10 16:14:54.000",
        // "eDate": "2018-10-18 16:14:54.000",
        // "dinnerType": "2",
        // "PageIndex":"2",
        // "PageSize":"3"
        JSONObject obj = new JSONObject();
        try {
            obj.put("Year", Year);
            obj.put("Month", Month);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().GetMonthRecordReport(body);
    }

    /**
     * 获取窗口
     *
     * @param Mac
     * @return
     */
    public Call<CommonListResponse<CanteenWindow>> GetCanteenWindows(String Mac) {
        JSONObject obj = new JSONObject();
        try {
            obj.put("MacAddress", Mac);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().GetCanteenWindows(body);
    }

    /**
     * 设置窗口
     *
     * @param MacAddress
     * @param CanTeenCode
     * @param WindowName
     * @return
     */
    public Call<CommonResponse> SaveCanteenWindows(String MacAddress, String CanTeenCode, String WindowName) {
        JSONObject obj = new JSONObject();
        try {
            obj.put("MacAddress", MacAddress);
            obj.put("CanTeenCode", CanTeenCode);
            obj.put("WindowName", WindowName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().SaveCanteenWindows(body);
    }

    /**
     * 获取窗口的消费金额与补助金额
     *
     * @param Mac
     * @return
     */
    public Call<CommonListResponse<WindowCostAmount>> GetWindowCostAmount(String Mac) {
        JSONObject obj = new JSONObject();
        try {
            obj.put("MacAddress", Mac);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().GetWindowCostAmount(body);
    }

    /**
     * 保存窗口消费金额与补助金额的设置
     *
     * @param MacAddress
     * @return
     */
    public Call<CommonResponse> SaveWindowCostAmount(String MacAddress, String DinnerCost) {
        JSONObject obj = new JSONObject();
        try {
            obj.put("MacAddress", MacAddress);
            obj.put("DinnerCost", DinnerCost);
        } catch (Exception e) {
            e.printStackTrace();
        }
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), obj.toString());
        return getAPIService().SaveWindowCostAmount(body);
    }
}