package com.sqx.modules.discSpinning.controller;

import com.sqx.common.utils.Constant;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
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("/userPrizeExchange")
@AllArgsConstructor
@Api(value = "用户奖品兑换", tags = {"用户奖品兑换"})
public class UserPrizeExchangeController {
    private final UserPrizeExchangeService userPrizeExchangeService;

    @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(@ApiIgnore @RequestParam Map<String, Object> params) {
        PageUtils page = userPrizeExchangeService.page(params);
        return Result.success().put("page", page);
    }

    @PostMapping("/deliver")
    @ApiOperation("发放")
    public Result exchange(@RequestBody UserPrizeExchange entity) {
        userPrizeExchangeService.deliver(entity);
        return Result.success();
    }
}
