package com.gree.mall.manager.controller.activity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.activity.PromotionApplyBean;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.activity.PromotionApplyLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

@Slf4j
@RestController
@Api(value = "优惠申请API", tags ={"优惠申请API"} )
@RequestMapping(value = "/promotion/apply", produces = "application/json; charset=utf-8")
public class PromotionApplyController {

    @Autowired
    PromotionApplyLogic promotionApplyLogic;


    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<IPage<PromotionApplyBean>> page(
            @ApiParam(value = "昵称手机号",required = true) @RequestParam String nickName,
            @ApiParam(value = "网点名称",required = true) @RequestParam String websitName,
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize,
            HttpServletRequest request
    ) throws Exception {
        IPage<PromotionApplyBean> list = promotionApplyLogic.list(nickName, websitName, pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "详情")
    public ResponseHelper<PromotionApplyBean> detail(
            @ApiParam(value = "id") @RequestParam(required = true)String id
    ) throws Exception {
        PromotionApplyBean detail = promotionApplyLogic.detail(id);
        return ResponseHelper.success(detail);
    }


    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public ResponseHelper save(
            @ApiParam(value = "id(不传就新增，传了就修改)",required = true) @RequestParam(required = false) String id,
            @ApiParam(value = "用户id",required = true) @RequestParam String userId,
            @ApiParam(value = "折扣率",required = true) @RequestParam BigDecimal rate,
            @ApiParam(value = "true=启用 false=禁用",required = true) @RequestParam Boolean status
    ) throws Exception {
        promotionApplyLogic.save(id,userId,rate,status);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public ResponseHelper delete(
            @ApiParam(value = "id") @RequestParam(required = true)String id
    ) throws Exception {
        promotionApplyLogic.delete(id);
        return ResponseHelper.success();
    }
}
