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.PartsRefundVO;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.material.PartsRefundLogic;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@Api(value = "配件返还API", tags ={"配件返还API"} )
@RequestMapping(value = "/material/parts/refund", produces = "application/json; charset=utf-8")
public class PartsRefundController {

    @Resource
    PartsRefundLogic partsRefundLogic;

    @PostMapping("list")
    @ApiOperation(value = "配件返还列表")
    public ResponseHelper<IPage<PartsRefundVO>> list(
            @ApiParam(value = "类型  NEW 新件返还  OLD 旧件返还 ", required = true) @RequestParam String type,
            @ApiParam(value = "状态  SUBMIT=待返还 OK=已返还") @RequestParam(required = false) String status,
            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize,
            HttpServletRequest request
    ) {
        IPage<PartsRefundVO> page = partsRefundLogic.list(type, status, pageNum, pageSize, request);
        return ResponseHelper.success(page);
    }

    @PostMapping("detail")
    @ApiOperation(value = "配件返还详情")
    public ResponseHelper<PartsRefundVO> detail(
            @ApiParam(value = "单号") @RequestParam String partsRetId,
            HttpServletRequest request
    ) {
        PartsRefundVO vo = partsRefundLogic.detail(partsRetId, request);
        return ResponseHelper.success(vo);
    }

    @PostMapping("count")
    @ApiOperation(value = "配件返还统计")
    public ResponseHelper<MyDataCountBean> count(
            @ApiParam(value = "类型  NEW 新件返还  OLD 旧件返还 ") @RequestParam String type,
            HttpServletRequest request
    ) {
        MyDataCountBean bean = partsRefundLogic.count(type, request);
        return ResponseHelper.success(bean);
    }
}
