package com.YuyeTech.HeartRate.game.controller;

import com.YuyeTech.HeartRate.VO.ResultVO;
import com.YuyeTech.HeartRate.game.gameInfo.projo.FcCategory;
import com.YuyeTech.HeartRate.dto.FcDTO;
import com.YuyeTech.HeartRate.game.gameInfo.service.FcCategoryReferenceService;
import com.YuyeTech.HeartRate.game.gameInfo.service.FcCategoryService;
import com.YuyeTech.HeartRate.game.gameInfo.service.FcInfoService;
import com.YuyeTech.HeartRate.utils.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:slambb
 * @date:2020/1/10
 */
@RestController
@RequestMapping("/FC")
@Slf4j
public class FcController {

    @Autowired
    private FcCategoryService fcCategoryService;

    @Autowired
    private FcInfoService fcInfoService;


    @Autowired
    private FcCategoryReferenceService fcCategoryReferenceService;

    @Value("${Fc.endTime}")
    private String getEndTime;
    /**
     * 获取游戏分类
     * @return
     */
    @GetMapping("/category_by_all")
    public ResultVO getFcCategoryByAll(){
       List<FcCategory> fcCategoryList =  fcCategoryService.findAll();
       return ResultVOUtil.success(fcCategoryList);
    }
    /**
     * 获取游戏分类
     * @return
     */
    @GetMapping("/category_by_type")
    public ResultVO getFcCategoryByType(@RequestParam(value = "categoryType", required = false) Integer categoryType){
        List<FcCategory> fcCategoryList =  fcCategoryService.findByType(categoryType);
        return ResultVOUtil.success(fcCategoryList);
    }
    /**
     * 根据游戏类目，获取游戏列表
     * @return
     */
//    @GetMapping("/list_from_category")
//    public ResultVO getGameListFromCategory(@RequestParam(value = "categoryType", required = false) Integer categoryType,
//                                            @RequestParam(value = "userId", required = false) String userId,
//                                            @RequestParam(value = "endTime", required = false) String endTime,
//                                            @RequestParam(value = "page", defaultValue = "1") Integer page,
//                                            @RequestParam(value = "size", defaultValue = "10") Integer size){
//        if(StringUtils.isEmpty(endTime)){
//            endTime = gameConfig.getEndTime();
//        }
//        //查询对应游戏数据
//        PageRequest request = PageRequest.of(page - 1, size);
//        List<GameDTO> gameDTOList =  gameInfoService.findList(userId,categoryType,endTime,request);
//
//        return ResultVOUtil.success(gameDTOList);
//    }

//    /**
//     * 根据Fc类目，获取Fc对应的列表
//     * @return
//     */
//    @GetMapping("/list_by_category")
//    public ResultVO getFcListByCategory(@RequestParam(value = "categoryType", required = false) Integer categoryType,
//                                        @RequestParam(value = "userId", required = false) String userId,
//                                        @RequestParam(value = "endTime", required = false) String endTime,
//                                        @RequestParam(value = "page", defaultValue = "1") Integer page,
//                                        @RequestParam(value = "size", defaultValue = "10") Integer size){
//        if(StringUtils.isEmpty(endTime)){
//            endTime = getEndTime;
//        }
//        //查询对应游戏数据
//        PageRequest request = PageRequest.of(page - 1, size);
//        List<FcDTO> fcDTOList =  fcInfoService.findList(userId,categoryType,endTime,request);
//
//        return ResultVOUtil.success(fcDTOList);
//    }

    /**
     * 根据Fc分类，查询引用类目对应的分类，获取Fc引用下分类对应的游戏列表
     * @return
     */
    @GetMapping("/list_by_category")
    public ResultVO getFcListByCategoryReference(@RequestParam(value = "categoryNumber", required = false) Integer categoryNumber,
                                        @RequestParam(value = "userId", required = false) String userId,
                                        @RequestParam(value = "endTime", required = false) String endTime,
                                        @RequestParam(value = "page", defaultValue = "1") Integer page,
                                        @RequestParam(value = "size", defaultValue = "10") Integer size){
        if(StringUtils.isEmpty(endTime)){
            endTime = getEndTime;
        }
        //查询对应游戏数据
        PageRequest request = PageRequest.of(page - 1, size);
        List<FcDTO> fcDTOList =  fcInfoService.findListByType(userId,categoryNumber,endTime,request);

        return ResultVOUtil.success(fcDTOList);
    }

}
