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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.miniapp.bean.material.MyDataCountBean;
import com.gree.mall.miniapp.bean.material.stock.WorkerStockAccBean;
import com.gree.mall.miniapp.bean.material.stock.WorkerStockBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.material.stock.MaterialGoodsStockLogic;
import com.gree.mall.miniapp.plus.entity.WebsitGoodsCategory;
import com.gree.mall.miniapp.plus.entity.WorkerStock;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(value = "辅配件-我的库存", tags ={"辅配件-我的库存"} )
@RequestMapping(value = "/material/worker/stock", produces = "application/json; charset=utf-8")
public class WorkerStockController {

    @Autowired
    MaterialGoodsStockLogic materialGoodsStockLogic;

    @PostMapping("/detail")
    @ApiOperation(value = "库存明细表头详情")
    public ResponseHelper<WorkerStock> detail(
            @RequestParam String id
    ) throws RemoteServiceException {
        WorkerStock detail = materialGoodsStockLogic.detail(id);
        return ResponseHelper.success(detail);
    }

    @PostMapping("/category/list")
    @ApiOperation(value = "我的库存分类")
    public ResponseHelper<List<WebsitGoodsCategory>> categoryList(
            @ApiParam(value = "网点id",required = false) @RequestParam(required = false) String websitId,
            @ApiParam(value = "M=辅材 P=配件",required = true) @RequestParam String goodsType
    ) throws RemoteServiceException {
        List<WebsitGoodsCategory> categoryList = materialGoodsStockLogic.websitGoodsCategoryList(websitId, goodsType);
        return ResponseHelper.success(categoryList);
    }

    @PostMapping("/list")
    @ApiOperation(value = "我的库存列表")
    public ResponseHelper<IPage<WorkerStockBean>> workerStockList(
            @ApiParam(value = "网点id",required = false) @RequestParam(required = false) String websitId,
            @ApiParam(value = "M=辅材 P=配件",required = true) @RequestParam String goodsType,
            @ApiParam(value = "小类id",required = false) @RequestParam String categoryId,
            @ApiParam(value = "页号",required = false) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = false) @RequestParam Integer pageSize
    ) throws RemoteServiceException {
        IPage<WorkerStockBean> workerStockBeanIPage = materialGoodsStockLogic.workerStockList(websitId, goodsType, categoryId, pageNum, pageSize);
        return ResponseHelper.success(workerStockBeanIPage);
    }


    @PostMapping("/acc/list")
    @ApiOperation(value = "我的库存明细列表")
    public ResponseHelper<IPage<WorkerStockAccBean>> workerStockAccList(
            @ApiParam(value = "网点id",required = false) @RequestParam(required = false) String websitId,
            @ApiParam(value = "商品id",required = true) @RequestParam String websitGoodsId,
            @ApiParam(value = "yyyy-MM格式",required = false) @RequestParam String month,
            @ApiParam(value = "发生方向 ADD=增加 SUB=减少 ",required = false) @RequestParam(required = false) String directFlag,
            @ApiParam(value = "页号",required = false) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = false) @RequestParam Integer pageSize
    ) throws RemoteServiceException {
        IPage<WorkerStockAccBean> workerStockAccIPage = materialGoodsStockLogic.workerStockAccList(websitId, websitGoodsId, month, directFlag,pageNum, pageSize);
        return ResponseHelper.success(workerStockAccIPage);
    }

    @PostMapping("/my/data/count")
    @ApiOperation(value = "我的数据统计")
    public ResponseHelper<MyDataCountBean> myDataCount() throws RemoteServiceException {
        MyDataCountBean bean = materialGoodsStockLogic.myDataCount();
        return ResponseHelper.success(bean);
    }

}
