package com.sqx.modules.app.controller;

import com.sqx.common.utils.Constant;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserPrizeExchange;
import com.sqx.modules.app.service.UserPrizeExchangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@RestController
@RequestMapping("/app/userPrizeExchange")
@AllArgsConstructor
@Api(value = "用户奖品兑换", tags = {"用户奖品兑换"})
public class AppUserPrizeExchangeController {
    private final UserPrizeExchangeService userPrizeExchangeService;

    @Login
    @GetMapping("/page")
    @ApiOperation("分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = Constant.PAGE, value = "当前页码，从1开始", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"),
    })
    public Result page(@RequestAttribute("userId") Long userId, @ApiIgnore @RequestParam Map<String, Object> params) {
        params.put("userId", userId);
        PageUtils page = userPrizeExchangeService.page(params);
        return Result.success().put("page", page);
    }

    @Login
    @PostMapping("/exchange")
    @ApiOperation("兑换")
    public Result exchange(@RequestAttribute("userId") Long userId, @RequestBody UserPrizeExchange entity) {
        userPrizeExchangeService.exchange(userId, entity);
        return Result.success();
    }

    @Login
    @PostMapping("/receive")
    @ApiOperation("领取满签奖励")
    public Result receive(@RequestAttribute("userId") Long userId) {
        userPrizeExchangeService.receive(userId);
        return Result.success();
    }
}
