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

import com.YuyeTech.HeartRate.annotation.Encrypt;
import com.YuyeTech.HeartRate.common.controller.*;
import com.YuyeTech.HeartRate.common.pojo.Result;
import com.YuyeTech.HeartRate.enums.ResultEnum;
import com.YuyeTech.HeartRate.game.userData.pojo.UserData;
import com.YuyeTech.HeartRate.game.userData.vo.UserDataVo;
import com.YuyeTech.HeartRate.game.userData.service.UserDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tPlat/userData/")
public class UserDataController extends CommonController<UserDataVo, UserData, String> {
    @Autowired
    private UserDataService userDataService;

    /**
     * 获取hitCount ，不是同一天，重置信息
     * @param userId
     * @return
     */
    @PostMapping("getHitCount")
    @Encrypt
    public Result<?> getUserDataByUserId(@RequestParam(value = "userId") String userId) {
        try {
            return Result.of(userDataService.getHitCount(userId));
        }catch (Exception e){
            return Result.of(null,false,ResultEnum.USER_DATA_DOES_NOT_EXIST);
        }

    }

    /**
     * 保存hitCount ,如果保存时候，不是同一天，从当前数据算起
     * @param userId
     * @return
     */
    @PostMapping("uploadHitCount")
    @Encrypt
    public Result<?> uploadUserDataByUserId(@RequestParam("userId") String userId,
                                                         @RequestParam("hitCount") Integer hitCount)
    {
        try {
            return Result.of(userDataService.uploadHitCount(userId,hitCount));
        }catch (Exception e){
            return Result.of(null,false,ResultEnum.USER_DATA_DOES_NOT_EXIST);
        }
    }
}
