package com.YuyeTech.TPlat.game.controller;

import com.YuyeTech.TPlat.dataobject.*;
import com.YuyeTech.TPlat.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author:slambb
 * @date:2021/8/4
 */
@RestController
@RequestMapping("/backstage_level")
@Slf4j
public class BackstageLevelController {

    @Autowired
    private LevelJumpService levelJumpService;




    @Value("${RSA.friendId.publicKey}")
    private String friendIdPublicKey;
    @Value("${RSA.friendId.privateKey}")
    private String friendIdPrivateKey;

    /**
     * 获取levelJump关卡列表
     *
     * @return
     */
    @GetMapping("/getLevelJumpList")
    public ModelAndView getLevelJumpList(
            @RequestParam(value = "numberType",defaultValue = "1") Integer numberType,
            Map<String, Object> map) {
             // map.put("list",levelJumpService.findLevelJumpsByNumberType(numberType, Sort.Direction.ASC));
        List<LevelJump> levelJumps = levelJumpService.findLevelJumpsAll();
        map.put("list",levelJumps);
        return new ModelAndView("/app/level", map);
    }

    /**
     * 添加新关卡
     * @param map
     * @return
     */
    @GetMapping("/add")
    public ModelAndView addLevel(Map<String, Object> map) {

        LevelJump levelJump = new LevelJump();
        map.put("levelJump", levelJump);

        //通过关卡条件
        List<LevelCondition> levelCondition = levelJumpService.findAllLevelCondition();
        //解锁条件
        map.put("levelCondition",levelCondition);
        //通过关卡获得荣誉
        List<LevelHonor> levelHonor = levelJumpService.findAllLevelHonor();
        map.put("levelHonor",levelHonor);
        // 0：随便生成一组跳的数据
        // 1：生成一组 左跳右跳
        // 2：生成一组 左跳右跳原地
        // 3：生成一组 左旋跳右旋跳
        // 4：生成一组 左旋跳右旋跳
        // 5：随便生成三组数据
        String[] signNames = new String[]{
                "随便生成一组跳的数据",
                "生成一组 左跳右跳",
                "生成一组 左跳右跳原地",
                "生成一组 左旋跳右旋跳",
                "生成一组 左旋跳右旋跳",
                "随便生成三组数据"
        };
        List<Map> signTypeMap = new ArrayList<>();
        for (int i=0;i<signNames.length;i++){
            Map signTypes = new HashMap();
            signTypes.put("value",i+"");
            signTypes.put("name",signNames[i]);
            signTypeMap.add(signTypes);
        }
        map.put("signTypeMap",signTypeMap);
        return new ModelAndView("/app/level-detail", map);
    }

    @GetMapping("/detailItem")
    public ModelAndView detailItem(
            @RequestParam(value = "levelId") Integer levelId,
            HttpServletRequest req,
            Map<String, Object> map) {
        LevelJump levelJump = levelJumpService.findById(levelId);
        map.put("levelJump", levelJump);
        //获取当前的解锁条件
        List<Integer> conditionUnlockList = Pattern.compile(",").splitAsStream(levelJump.getConditionUnlock()).map((x) -> Integer.parseInt(x))
                .collect(Collectors.toList());
        map.put("unlockList",conditionUnlockList);
        //通过关卡条件
        List<LevelCondition> levelCondition = levelJumpService.findAllLevelCondition();
        //解锁条件
        map.put("levelCondition",levelCondition);
        //通过关卡获得荣誉
        List<LevelHonor> levelHonor = levelJumpService.findAllLevelHonor();
        map.put("levelHonor",levelHonor);
        // 0：随便生成一组跳的数据
        // 1：生成一组 左跳右跳
        // 2：生成一组 左跳右跳原地
        // 3：生成一组 左旋跳右旋跳
        // 4：生成一组 左旋跳右旋跳
        // 5：随便生成三组数据
        String[] signNames = new String[]{
                "随便生成一组跳的数据",
                "生成一组 左跳右跳",
                "生成一组 左跳右跳原地",
                "生成一组 左旋跳右旋跳",
                "生成一组 左旋跳右旋跳",
                "随便生成三组数据"
        };
        List<Map> signTypeMap = new ArrayList<>();
        for (int i=0;i<signNames.length;i++){
            Map signTypes = new HashMap();
            signTypes.put("value",i+"");
            signTypes.put("name",signNames[i]);
            signTypeMap.add(signTypes);
        }
        map.put("signTypeMap",signTypeMap);
        return new ModelAndView("/app/level-detail", map);
    }


}
