package com.gree.mall.miniapp.controller.acitivy;

import com.gree.mall.miniapp.bean.activity.PromotionActivityBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.acitivy.PromotionActivityLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "扫码活动单API", tags ={"扫码活动单API"} )
@RequestMapping(value = "/promotion/activity", produces = "application/json; charset=utf-8")
public class PromotionActivityController {

    @Resource
    PromotionActivityLogic promotionActivityLogic;

    @PostMapping("/list")
    @ApiOperation(value = "报名记录-列表")
    public ResponseHelper<List<PromotionActivityBean>> list(
            @ApiParam(value = "设置活动id") @RequestParam(required = false) String promotionQuestionnaireId,
            @ApiParam(value = "页号") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(value = "页大小") @RequestParam(required = false, defaultValue = "-1")  Integer pageSize
    ) {
        List<PromotionActivityBean> page = promotionActivityLogic.list(pageNum, pageSize, promotionQuestionnaireId);
        return ResponseHelper.success(page);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "报名记录-详情")
    public ResponseHelper<PromotionActivityBean> detail(
            @ApiParam(value = "id", required = true) @RequestParam String promotionActivityId
    ) throws RemoteServiceException {
        PromotionActivityBean bean = promotionActivityLogic.detail(promotionActivityId);
        return ResponseHelper.success(bean);
    }

    @PostMapping("/add")
    @ApiOperation(value = "报名记录-新增")
    public ResponseHelper add(
            HttpServletRequest request,
            @RequestBody PromotionActivityBean bean
    ) throws Exception {
        promotionActivityLogic.add(request, bean);
        return ResponseHelper.success();
    }

}
