import { AppService, TyExternalApiClient, axiosInstance, throwIfResCodeNoSuccess } from "../refs/nslib"
/**
 * 
 * @date 2022-08-16 10:26:18
 * @author 侯洪莉
 */
class Helper {
    /**
     * 验证参数是否为空
     * @param data 参数
     * @param mustFields 需要验证的参数集合 string,number,object,bigint,boolean,symbol,undefined,function
     */
    static ParamsIsNullCheck(data, mustFields): any {
        for (let i = 0; i < mustFields.length; i++) {
            let item = mustFields[i];
            let val = data[item.value];
            let type = typeof (val);
            switch (type) {
                case 'string':
                    if (val == null || val == '' || !val.length) {
                        return item.text + "为必填项！";
                    }
                    break;
                case 'number':
                    if (Object.is(val, NaN)) {
                        return item.text + "为必填项！";
                    }
                    break;
                case 'object':
                    if (val == null || !val.length) {
                        return item.text + "为必填项！";
                    }
                    break;
                default:
                    if (val == null) {
                        return item.text + "为必填项！";
                    }
                    break;
            }
        }
        return true;
    }

    /**
     * 获取消费统计情况
     * @param {string} parkId  车场id
     * @param {string} plateNo 车牌号
     * @param {string} cardNo 入场取票号/无牌车入场的卡号
     */
    static async getPaymentCount(data) {
        const { parkId, plateNo = '', inTime = '', payMethod = '', startTime = '', endTime = '', pileId: paySource = '' } = data;
        // 收费终端为充电桩
        const payType = 1009;
        let count = 0, time = 0, money = 0;

        const options = {
            parkId: parkId,
            plateNo: plateNo,
            pageIndex: 1,
            pageSize: 100,
            inTime: inTime || undefined,
            startTime: startTime || undefined,
            endTime: endTime || undefined,
        }


        const axiosResponse = await axiosInstance.post('/api/wec/GetParkingPaymentList', options)
        throwIfResCodeNoSuccess(axiosResponse.data);
        const listRst = axiosResponse.data
        // if (listRst.resCode != 0) {
        //     return { count, time, money };
        // }


        for (let item of listRst.data.plateList) {

            if ((item.payMethod == payMethod || !payMethod) && item.payType == payType && (item.paySource == parseInt(paySource) || !paySource)) {
                count += 1;
                money += item.freeMoney;
                time += item.freeTime;
            }
        }
        return { count, time, money };

    }


}

export { Helper }