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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.bean.activity.fullpiece.PromotionFullPieceBean;
import com.gree.mall.manager.bean.activity.fullpiece.PromotionFullPieceListVO;
import com.gree.mall.manager.bean.activity.fullpiece.PromotionFullPieceOrderVO;
import com.gree.mall.manager.bean.activity.fullpiece.PromotionFullPieceVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.activity.PromotionFullPieceLogic;
import com.gree.mall.manager.plus.entity.OrderDetail;
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 java.util.Map;

@Slf4j
@RestController
@Api(value = "满件打折活动", tags ={"满件打折活动"} )
@RequestMapping(value = "/promotion/full/piece", produces = "application/json; charset=utf-8")
public class PromotionFullPieceController {

    @Autowired
    PromotionFullPieceLogic promotionFullPieceLogic;

    @GetMapping("/list")
    @ApiOperation("列表")
    public ResponseHelper<PromotionFullPieceListVO> list(
            @ApiParam(value = "1=进行中 2=未开始 3=已过期") @RequestParam(required = false)Integer status,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize){
        IPage<PromotionFullPieceListVO> list = promotionFullPieceLogic.list(status,pageNum, pageSize);
        return ResponseHelper.success(list);
    }

    @GetMapping("/total")
    @ApiOperation("根据状态统计活动数量")
    public ResponseHelper<Map<String, Integer>> totalByStatus(){
        Map<String, Integer> map = promotionFullPieceLogic.totalByStatus();
        return ResponseHelper.success(map);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存活动(有id修改，没id新增)")
    public ResponseHelper save(
            @ApiParam(value = "object") @RequestBody(required = false) PromotionFullPieceBean bean
    ) throws Exception {
        promotionFullPieceLogic.save(bean);
        return ResponseHelper.success();
    }

    //PromotionFullPieceVO
    @GetMapping("/detail")
    @ApiOperation(value = "活动详情")
    public ResponseHelper<PromotionFullPieceVO> detail(
            @ApiParam(value = "id") @RequestParam String id
    ) throws Exception {
        PromotionFullPieceVO detail = promotionFullPieceLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @GetMapping("/order/detail")
    @ApiOperation("订单详情")
    public ResponseHelper<IPage<OrderDetail>> orderDetail(
            @ApiParam(value = "活动id") @RequestParam String id,
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize
    ){
        IPage<PromotionFullPieceOrderVO> page = promotionFullPieceLogic.orderDetail(id, pageNum, pageSize);
        return ResponseHelper.success(page);
    }

}
