const Api = require('../net/Api');

class DrawApi {

    /**
     * 开始抽奖 
     * @param typeId [long] 1 为第一个抽奖 2 为第二个抽奖 3 为第三个抽奖
     * @param isDiamond [int] 是否为钻石抽奖。1是0不 (只有第一个抽奖需要)
     */
    static startLottery(typeId, isDiamond = 0, success, fail) {

        let url = "/lottery/startLottery";
        
        let data = {type: typeId};
        if (typeId == 1) {
            data.isDiamond = isDiamond;
        } else {
            data.isDiamond = 1;
        }
        console.log(data);
        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     *  获取抽奖相关信息
     */
    static getLotteryInfo(success, fail) {
        let url = "/lottery/getLotteryInfo.do";
        Api.httpGet(this.setRequestBody(url, {}, success, fail));
    }

    // 生成一个 RequestBody, 总是要写重复代码, 太恶心了
    static setRequestBody(url, data, success, fail) {
        let requestBody = {
            url: url,
            data: data,
            success: success,
            fail: fail,
            complete: () => {

            }
        };
        return requestBody;
    }
}    
module.exports = DrawApi;