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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.activity.PromotionGroupBean;
import com.gree.mall.manager.bean.activity.PromotionGroupList;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.activity.PromotionDiscountLogic;
import com.gree.mall.manager.plus.entity.PromotionDiscount;
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.util.Map;

@Slf4j
@RestController
@Api(value = "折扣活动API", tags ={"折扣活动API"} )
@RequestMapping(value = "/promotion/discount", produces = "application/json; charset=utf-8")
public class PromotionDiscountController {

    @Autowired
    PromotionDiscountLogic promotionDiscountLogic;


    @GetMapping("/list")
    @ApiOperation(value = "折扣活动-列表")
    public ResponseHelper<IPage<PromotionDiscount>> page(
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize,
            HttpServletRequest request
    ) throws Exception {
        IPage<PromotionDiscount> list = promotionDiscountLogic.list(pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "折扣活动-详情")
    public ResponseHelper<PromotionDiscount> detail(
            @ApiParam(value = "id") @RequestParam(required = true)String id
    ) throws Exception {
        PromotionDiscount detail = promotionDiscountLogic.detail(id);
        return ResponseHelper.success(detail);
    }


    @PostMapping("/add")
    @ApiOperation(value = "折扣活动-新增")
    public ResponseHelper add(
            @ApiParam(value = "object") @RequestBody(required = true)PromotionDiscount promotionDiscount
    ) throws Exception {
        promotionDiscountLogic.add(promotionDiscount);
        return ResponseHelper.success();
    }


    @PostMapping("/update")
    @ApiOperation(value = "折扣活动-修改")
    public ResponseHelper update(
            @ApiParam(value = "object") @RequestBody(required = false)PromotionDiscount promotionDiscount
    ) throws Exception {
        promotionDiscountLogic.update(promotionDiscount);
        return ResponseHelper.success();
    }

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

}
