package com.YuyeTech.HeartRate.game.versionCode.controller;

import com.YuyeTech.HeartRate.annotation.Decrypt;
import com.YuyeTech.HeartRate.annotation.Encrypt;
import com.YuyeTech.HeartRate.common.pojo.PageInfo;
import com.YuyeTech.HeartRate.common.pojo.Result;
import com.YuyeTech.HeartRate.game.versionCode.projo.VersionCode;
import com.YuyeTech.HeartRate.game.versionCode.service.VersionCodeService;
import com.YuyeTech.HeartRate.game.versionCode.vo.VersionCodeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author:slambb
 * @date:2023/08/29
 */
@RestController
@RequestMapping("/backstage_version_code")
@Slf4j
public class BackstageVersionCodeController {

    @Autowired
    private VersionCodeService versionCodeService;

    /**
     * 前端view跳转,配置菜单路径
     * 设置默认参数
     *
     * @return
     */
    @GetMapping("gotoView")
    public ModelAndView gotoView() {
        ModelAndView modelAndView = new ModelAndView("client/statesInfo");
        return modelAndView;
    }

    /**
     * 分页查询数据
     *
     * @param vo
     * @return
     */
    @PostMapping("findAll")
    @Decrypt
    @Encrypt
    public Result<PageInfo<VersionCodeVo>> findAll(VersionCodeVo vo) {
        return versionCodeService.page(vo);
    }


    /**
     * 删除数据
     * 删除时候，需要更新缓存列表
     *
     * @param id
     * @return
     */
    @PostMapping("delete")
    @Decrypt
    @Encrypt
    public Result delete(@RequestParam("id") Integer id) {
        return versionCodeService.delete(id);
    }


    @PostMapping("saveVersionCodeInfo")
    @Decrypt
    @Encrypt
    public Result saveVersionCodeInfo(@RequestParam("id") Integer id,
                               @RequestParam("limitPlatform") Integer limitPlatform) {
        VersionCodeVo versionCode = versionCodeService.getVo(id);
        versionCode.setLimitPlatform(limitPlatform);
        return versionCodeService.save(versionCode);
    }

    @PostMapping("saveShowConfigInfo")
    @Decrypt
    @Encrypt
    public Result saveShowConfigInfo(@RequestParam("id") Integer id,
                                      @RequestParam("showConfig") String showConfig) {
        VersionCodeVo versionCode = versionCodeService.getVo(id);
        versionCode.setShowConfig(showConfig);
        return versionCodeService.save(versionCode);
    }
}
