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

class HomeApi {

    /**
     * 获取目标用户的建筑
     * @param targetUid [long] 目标用户，当前用户就传自己的uid 的值
     * @param cityId [long] 城市 id
     */
    static getUserBuildings(targetUid, cityId, success, fail) {

        let url = "/building/getUserBuildings.do";

        let data = {
            targetUid: targetUid,
            cityId: cityId,
        };

        Api.httpGet(this.setRequestBody(url, data, success, fail));
    }

    /**
     *  升级建筑
     *  @param buildingId   [int] 建筑Id
     *  @param cityId       [int] 城市id
     *  @param grossIncome  [int] 当前总金币数
     *  @param grossRate    [int] 自动收入金额
     *  @param level        [int] 建筑等级
     *  @param stars        [int] 星星数
     *
     * */
    static buildingUpGrade(formmInfoJson, success, fail) {

        let url = "/building/upGrade.do";

        let data = {
            formInfo: formmInfoJson,
        };

        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     *  获取首页好友列表
     * */
    static getFriends(success, fail) {
    
        let url = "/friend/getIndexList.do";

        Api.httpGet(this.setRequestBody(url, {}, success, fail));
    }

    /**
     * 主界面艺人管理列表
     */
    static getFriendManageList(success, fail) {

        let url = "/friend/getManageList.do";

        Api.httpGet(this.setRequestBody(url, {}, success, fail));
    }

    /**
     * 上报接口
     * @param {*} reportFormInfo {"grossIncome":1000,"grossRate":10000,"stars":1}
     * @param {*} success 
     * @param {*} fail 
     */
    static userReportGross(reportFormInfo, success, fail) {

        let url = "/building/report.do";

        let data = {
            reportFormInfo: reportFormInfo,
        };

        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 获取好友艺人列表
     * @param {int} fid 好友uid 
     * @param {*} success 
     * @param {*} fail 
     */
    static friendGetArtists(fid, success, fail) {

        let url = "/friend/getArtists.do";

        let data = {
            fid: fid,
        };

        Api.httpGet(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 获取好友艺人列表
     * @param {int} buildingId 建筑对应的 buildingId
     * @param {*} success 
     * @param {*} fail 
     */
    static friendGetArtistsByBuildingId(targetUid, buildingId, success, fail) {

        let url = "/friend/getArtists4Station.do";

        let data = {
            targetUid: targetUid,
            buildingId: buildingId,
        };
        Api.httpGet(this.setRequestBody(url, data, success, fail));
    }


    /**
     * 艺人入驻
     * @param {*} formmInfoJson 
     * @param {*} success 
     * @param {*} fail 
     */
    static friendStation(formmInfoJson, success, fail) {
        let url = "/friend/station.do";

        let data = {
            form: formmInfoJson,
        };

        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 艺人的驱赶召回
     * @param {*} formmInfoJson 
     * @param {*} success 
     * @param {*} fail 
     */
    static friendExpelRecall(artistUid, success, fail) {
        let url = "/friend/expelRecall.do";

        let data = {
            artistUid: artistUid,
        };

        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 获取用户对应建筑入驻的艺人列表
     * @param {*} targetUid 目标用户(是谁的家园，目标用户就是谁)
     * @param {*} buildingId 建筑id
     * @param {*} success 
     * @param {*} fail 
     */
    static friendGetArtistsInBuilding(targetUid, buildingId, success, fail) {

        let url = "/friend/getArtistsInBuilding.do";

        let data = {
            targetUid: targetUid,
            buildingId: buildingId
        };
        Api.httpGet(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 入驻艺人收益
     * @param {*} formmInfoJson 
     * @param {*} success 
     * @param {*} fail 
     */
    static friendGetBenefit(artistUid, success, fail) {
        let url = "/friend/getBenefit.do";

        let data = {
            artistUid: artistUid,
        };
        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

    /**
     * 举报艺人
     * @param {*} formmInfoJson 
     * @param {*} success 
     * @param {*} fail 
     */
    static friendReportArtist(artistUid, success, fail) {
        let url = "/friend/reportArtist.do";

        let data = {
            artistUid: artistUid,
        };
        Api.httpPost(this.setRequestBody(url, data, success, fail));
    }

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

            }
        };
        return requestBody;
    }
}

module.exports = HomeApi;