package com.td.WaDa;

import cn.hutool.json.JSONUtil;
import com.td.WaDa.common.pojo.Result;
import com.td.WaDa.game.comconfigland.service.ComConfigLandService;
import com.td.WaDa.game.comconfigland.vo.ComConfigLandVo;
import com.td.WaDa.game.commallseed.controller.ComMallSeedController;
import com.td.WaDa.game.commallseed.vo.ComMallSeedVo;
import com.td.WaDa.game.complayercultivate.controller.ComPlayerCultivateController;
import com.td.WaDa.game.complayercultivate.serivce.ComPlayerCultivateSerivce;
import com.td.WaDa.game.complayergoods.controller.ComPlayerGoodsController;
import com.td.WaDa.game.complayerland.controller.ComPlayerLandController;
import com.td.WaDa.game.complayerland.vo.ComPlayerLandAndPlantVo;
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;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ComPlayerCultivateTests {
    private String userId = "1002";
    private int configlandid = 25;
    @Autowired
    private ComPlayerLandController comPlayerLandController;
    @Autowired
    private ComMallSeedController comMallSeedController;
    @Autowired
    private ComPlayerGoodsController comPlayerGoodsController;
    @Autowired
    private ComConfigLandService comConfigLandService;
    @Autowired
    private ComPlayerCultivateController comPlayerCultivateController;
    @Autowired
    private ComPlayerCultivateSerivce comPlayerCultivateSerivce;

    //需要测试 多天上线以后情况

    //解锁某个土地 【新增功能】【测试完】
    @Test
    public void buyLand() {
        Result<?> comPlayerLandAndPlantVoResult = comPlayerCultivateController.payLand(userId, 26);
        print(comPlayerLandAndPlantVoResult);
    }

    //种种子选择放养数量 【修改完毕】【测试完】
    @Test
    public void plantFunction() {
        //测试重复种植
//        print(comPlayerLandController.plantFunction(userId, configlandid, 11, 1000));
        //测试种植数量大于土地最大承受
//        print(comPlayerLandController.plantFunction(userId, 26, 11, 1000));
        //测试种植 包里没有的种子
//        print(comPlayerLandController.plantFunction(userId, 26, 11, 20));
        //测试种子数量不足
//        print(comPlayerLandController.plantFunction(userId, 26, 10, 20));
        print(comPlayerLandController.plantFunction(userId, 26, 10, 2));
    }

    //喂养就是购买粮食 【修改完毕】【测试完】
    @Test
    public void buyFood() {
        //需要计算一下 有多少只动物。要喂多少天。就算一下一共花多少钱。还得插一个喂养明细。
//       print( comPlayerDogController.addFoodFunction(userId,6,1));
//       print( comPlayerCultivateSerivce.buyFood(userId, configlandid));
//       print( comPlayerCultivateSerivce.buyFood(userId, 26));
        print(comPlayerCultivateSerivce.buyFood(userId, 26));
    }


    //获取某个人所有土地 【修改完毕】【测试完】,需要查询喂养记录，重新计算成熟日期
    @Test
    public void getLandByUserId() {
        Result<List<ComPlayerLandAndPlantVo>> landFunction = comPlayerLandController.getLandFunction("1002", "1002");
        print(landFunction);
    }

    //偷果实 【修改完毕 待测试】
    @Test
    public void stealFruitFunction() {
        comPlayerGoodsController.stealFruitFunction(userId, userId, configlandid);
    }
    //收货，成熟 【修改完毕 测试完】，一天不喂延长2天
    @Test
    public void addFruitFunction() {
        comPlayerGoodsController.addFruitFunction(userId, 26);
    }


    //获取所有土地 【一点没变】【测试完】
    @Test
    public void getLands() {
        Result<List<ComConfigLandVo>> list = comConfigLandService.list(new ComConfigLandVo());
        print(list);
    }

    //获取所有种子列表 【一点没变】【测试完】
    @Test
    public void getSeed() {
        Result<List<ComMallSeedVo>> snbFunction = comMallSeedController.getSNBFunction(userId);
        print(snbFunction);
    }

    //购买种子【一点没变】【测试完】这块逻辑是只要钱够，种子id对就没问题
    @Test
    public void buySeeds() {
        comMallSeedController.snbBuySeedsFunction(userId, 200, 10);
    }

    //购买种子，进入仓库【一点没变】【测试完】
    @Test
    public void getGood() {
        Result<Map> seedAndFruitFunction = comPlayerGoodsController.getSeedAndFruitFunction(userId);
        print(seedAndFruitFunction);
    }

    private void print(Result result) {
        System.out.println(JSONUtil.toJsonStr(result.getData()));
    }
}
