package com.liquidnet.service.sweet.controller;


import com.liquidnet.service.base.PagedResult;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.candy.vo.CandyCouponPreviewVo;
import com.liquidnet.service.sweet.dto.vo.IntegralActivityDrawVo;
import com.liquidnet.service.sweet.dto.vo.IntegralActivityPrizeApiVo;
import com.liquidnet.service.sweet.service.ISweetIntegralActivityDrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 积分活动抽奖记录表 前端控制器
 * </p>
 *
 * @author jiangxiulong
 * @since 2021-10-26
 */
@Api(tags = "活动-积分抽奖")
@RestController
@RequestMapping("/integralActivityDraw")
public class SweetIntegralActivityDrawController {
    @Autowired
    private ISweetIntegralActivityDrawService activityDrawService;

    @PostMapping("create")
    @ApiOperation("用户抽奖")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "integralActivityId", value = "活动id", required = true)
    })
    public ResponseDto<IntegralActivityPrizeApiVo> create(
            @RequestParam("integralActivityId") String integralActivityId
    ) {
        return activityDrawService.create(integralActivityId);
    }

    @GetMapping("drawList")
    @ApiOperation("用户抽奖记录列表")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "integralActivityId", value = "活动id", required = true),
            @ApiImplicitParam(type = "query", dataType = "Integer", name = "pageNum", value = "分页", required = true)
    })
    public ResponseDto<PagedResult<IntegralActivityDrawVo>> drawList(
            @RequestParam("integralActivityId") String integralActivityId,
            @RequestParam("pageNum") Integer pageNum
    ) {
        return activityDrawService.drawList(integralActivityId, pageNum);
    }

    @GetMapping("winPrizeUser")
    @ApiOperation("活动中奖用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "integralActivityId", value = "活动id", required = true)
    })
    public ResponseDto<List<IntegralActivityDrawVo>> winPrizeUser(
            @RequestParam("integralActivityId") String integralActivityId
    ) {
        return activityDrawService.winPrizeUser(integralActivityId);
    }

    @GetMapping("detail/{drawId}")
    @ApiOperation("抽奖详情")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "path", dataType = "String", name = "drawId", value = "drawId", required = true)
    })
    public ResponseDto<IntegralActivityDrawVo> detail(
            @PathVariable("drawId") String drawId
    ) {
        return activityDrawService.detail(drawId);
    }

    @PostMapping("perfectAddress")
    @ApiOperation("中奖完善收货地址")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "drawId", value = "中奖ID", required = true),
            @ApiImplicitParam(type = "query", dataType = "String", name = "receivingAddressesId", value = "adam收货地址addresses_id", required = true)
    })
    public ResponseDto perfectAddress(
            @RequestParam("drawId") String drawId,
            @RequestParam("receivingAddressesId") String receivingAddressesId
    ) {
        return activityDrawService.perfectAddress(drawId, receivingAddressesId);
    }

    @PostMapping("collectCoupon")
    @ApiOperation("领取券")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "couponId", value = "券id", required = true),
            @ApiImplicitParam(type = "query", dataType = "String", name = "drawId", value = "抽奖id", required = true)
    })
    public ResponseDto collectCoupon(
            @RequestParam("couponId") String couponId,
            @RequestParam("drawId") String drawId
    ) {
        return activityDrawService.collectCoupon(couponId, drawId);
    }

    @PostMapping("couponList")
    @ApiOperation("奖品对应的券列表")
    @ApiImplicitParams({
            @ApiImplicitParam(type = "query", dataType = "String", name = "prizeId", value = "奖品id", required = true),
            @ApiImplicitParam(type = "query", dataType = "String", name = "integralActivityId", value = "活动id", required = true),
            @ApiImplicitParam(type = "query", dataType = "int", name = "pageNum", value = "分页")
    })
    public ResponseDto<List<CandyCouponPreviewVo>> couponList(
            @RequestParam("prizeId") String prizeId,
            @RequestParam("integralActivityId") String integralActivityId,
            @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
    ) {
        return activityDrawService.couponList(prizeId, integralActivityId);
    }

}
