package shop.alien.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.store.ActivitySignInConfig;
import shop.alien.entity.store.UserSignInRecord;
import shop.alien.entity.store.vo.SignInVo;
import shop.alien.entity.store.vo.UserSignInRecordVo;
import shop.alien.store.service.SignInService;

@Api(tags = {"二期-用户签到"})
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/userSign")
@RequiredArgsConstructor
public class SignInController {
    private final SignInService signInService;

    /**
     * 用户签到
     */
    @ApiOperation("用户签到")
    @ApiOperationSupport(order = 1)
    @GetMapping("/signIn")
    public R<UserSignInRecordVo> signIn(@RequestParam("userId") Integer userId) {
        log.info("SignInController.signIn, userid = {}", userId);
        UserSignInRecordVo userSignInRecordVo = signInService.signIn(userId);
        return R.data(userSignInRecordVo);
    }

    @ApiOperation("获取活动配置信息")
    @ApiOperationSupport(order = 2)
    @GetMapping("/getActivitySignInConfigInfo")
    public R<ActivitySignInConfig> getActivitySignInConfigInfo() {
        log.info("SignInController.getActivitySignInConfigInfo");
        ActivitySignInConfig activitySignInConfig = signInService.getActivitySignInConfigInfo();
        return R.data(activitySignInConfig);
    }

    @ApiOperation("获取是否签到")
    @ApiOperationSupport(order = 3)
    @GetMapping("/checkSignInStatus")
    public R<Boolean> checkSignInStatus(@RequestParam("userId") Integer userId) {
        log.info("SignInController.checkSignInStatus, {}", userId);
        boolean result = signInService.checkSignInStatus(userId);
        return R.data(result);
    }

    @ApiOperation("获取签到相关信息")
    @ApiOperationSupport(order = 4)
    @GetMapping("/getUserSignInInfo")
    public R<SignInVo> getUserSignInInfo(@RequestParam("userId") Integer userId, @RequestParam("num") Integer num) {
        log.info("SignInController.getUserSignInInfo");
        SignInVo signInVo = signInService.getUserSignInInfo(userId, num);
        return R.data(signInVo);
    }

    @ApiOperation("获取签到记录列表（分页）")
    @ApiOperationSupport(order = 5)
    @GetMapping("/getUserSignInRecordList")
    public R<IPage<UserSignInRecord>> getUserSignInRecordList(@RequestParam(defaultValue = "1") int pageNum,
                                            @RequestParam(defaultValue = "10") int pageSize,
                                            @RequestParam(required = true) int userId){
        log.info("SignInController.getUserSignInRecordList");
        IPage<UserSignInRecord> userSignInRecordList = signInService.getUserSignInRecordList(pageNum, pageSize,userId);
        return R.data(userSignInRecordList);
    }
}
