package com.td.boss;

import cn.hutool.json.JSONUtil;
import com.td.boss.common.pojo.Result;
import com.td.boss.common.service.ComConfigService;
import com.td.boss.game.complayersattri.controller.ComPlayersLuckyController;
import com.td.boss.game.complayersattri.vo.ComPlayersLuckyLandLevelUpVo;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * 工具模块
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ComPlayerLuckyTests {
    private String userId = "1002";
    private int landId = 169;
    private int levelId = 2;

    @Autowired
    ComPlayersLuckyController comPlayersLuckyController;

    @Autowired
    private ComConfigService configService;

    @Test
    public void getLandTools() {
        Result<?> landTools = comPlayersLuckyController.getLandTools();
        System.out.println(JSONUtil.toJsonStr(landTools));
    }

    @Test
    public void getLandLevelUp() {
        Result<?> landLevelUp = comPlayersLuckyController.getLandLevelUp();
        System.out.println(JSONUtil.toJsonStr(landLevelUp));
    }

    /**
     * 测试使用工具
     */
    @Test
    public void useLuckyTools() {
        Result<?> result_tool = comPlayersLuckyController.useLuckyTools(userId, 9999999, landId);
        Assert.assertFalse(result_tool.isFlag());

        Result<?> result_land = comPlayersLuckyController.useLuckyTools(userId, 2, 9999999);
        Assert.assertFalse(result_land.isFlag());

        Result<?> result_endDate = comPlayersLuckyController.useLuckyTools(userId, 2, 3);
        Assert.assertFalse(result_endDate.isFlag());

        Result<?> result_user = comPlayersLuckyController.useLuckyTools("9999999", 2, landId);
        Assert.assertFalse(result_user.isFlag());

        Result<?> result = comPlayersLuckyController.useLuckyTools(userId, 2, landId);
        Assert.assertTrue(result.isFlag());
    }

    /**
     * 测试土地升级
     */
    @Test
    public void landLevelUp() {
        Result<?> result_user = comPlayersLuckyController.landLevelUp("9999999", levelId, landId);
        Assert.assertFalse(result_user.isFlag());
        Result<?> result_level = comPlayersLuckyController.landLevelUp(userId, 9999999, landId);
        Assert.assertFalse(result_level.isFlag());
        Result<?> result_land = comPlayersLuckyController.landLevelUp(userId, levelId, 9999999);
        Assert.assertFalse(result_land.isFlag());
        //幸运值不够
        Result<?> result_no = comPlayersLuckyController.landLevelUp("1024", levelId, 3);
        Assert.assertFalse(result_no.isFlag());
        //测试到期
        Result<?> result_endDate = comPlayersLuckyController.useLuckyTools(userId, 2, 170);
        Assert.assertFalse(result_endDate.isFlag());
        //测试正常升级
        Result<?> result = comPlayersLuckyController.landLevelUp(userId, levelId, landId);
        Assert.assertTrue(result.isFlag());
        //重复升级
        Result<?> result2 = comPlayersLuckyController.landLevelUp(userId, levelId, landId);
        Assert.assertFalse(result2.isFlag());
    }

    /**
     * 兑换snb
     */
    @Test
    public void toSNB() {
        Result<?> result_user = comPlayersLuckyController.toSNB("9999999", 50 * 20);
        Assert.assertFalse(result_user.isFlag());
        //幸运值不够
        Result<?> result_land = comPlayersLuckyController.toSNB(userId, 100000);
        Assert.assertFalse(result_land.isFlag());
        //幸运值边界
        Result<?> result_land1 = comPlayersLuckyController.toSNB(userId, 999);
        Assert.assertFalse(result_land1.isFlag());
        Result<?> result_land2 = comPlayersLuckyController.toSNB(userId, 100001);
        Assert.assertFalse(result_land2.isFlag());
        //正常兑换
        Result<?> result = comPlayersLuckyController.toSNB(userId, 50 * 20);
        System.out.println(JSONUtil.toJsonStr(result));
    }

    @Test
    public void getConfig(){
        List<ComPlayersLuckyLandLevelUpVo> list = configService.selectLandLevel();
        String json = JSONUtil.toJsonStr(list);
        System.out.println(json);
    }
}
