package com.bonus.canteen.core.supply.controller;

import com.bonus.canteen.core.supply.dto.*;
import com.bonus.canteen.core.supply.service.DrpOrderGoodsDetailServiceV2;
import com.bonus.canteen.core.supply.service.DrpSupplierComeGoService;
import com.bonus.canteen.core.supply.vo.DrpOrderGoodsDetailVO;
import com.bonus.canteen.core.supply.vo.DrpSupplierComeAndGoPageVO;
import com.bonus.canteen.core.supply.vo.DrpSupplierMaterialIntoAndOutPageVO;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping({"/drp/supplier-come-go"})
@Api( tags = {"应收应付"})
public class SupplierComeGoController extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(SupplierComeGoController.class);

   @Resource
   private DrpSupplierComeGoService drpSupplierComeGoService;

   @Resource
   private DrpOrderGoodsDetailServiceV2 drpOrderGoodsDetailService;

   @GetMapping({"/supplier-material/into-and-out/page"})
   @ApiOperation("供应商货品记录")
   public TableDataInfo pageSupplierMaterialIntoAndOut( DrpSupplierMaterialIntoAndOutPageDTO content) {
      startPage();
      List<DrpSupplierMaterialIntoAndOutPageVO> list = this.drpSupplierComeGoService.pageSupplierMaterialIntoAndOut(content);
      return getDataTable(list);
   }

   @GetMapping({"/supplier/come-and-go/page"})
   @ApiOperation("供应商往来订单")
   public TableDataInfo pageSupplierComeAndGo( DrpSupplierComeAndGoPageDTO content) {
      startPage();
      List<DrpSupplierComeAndGoPageVO> list =this.drpSupplierComeGoService.pageSupplierComeAndGo(content);
      return getDataTable(list);
   }

   @GetMapping({"/supplier/come-and-go/page-detail"})
   @ApiOperation("供应商往来订单明细")
   public List<DrpOrderGoodsDetailVO> pageSupplierComeAndGoDetail(@Param("orderGoodsId") String orderGoodsId) {
      return this.drpOrderGoodsDetailService.getDrpOrderGoodsDetailVOListByOrderGoodsId(orderGoodsId);
   }


   @PostMapping({"/apply-pay"})
   @ApiOperation("申请付款")
   public AjaxResult applyPay(@RequestBody @Valid DrpComeAndGoApplyPayDTO content) {
      this.drpSupplierComeGoService.applyPay(content);
      return  success();
   }

   @PostMapping({"/commit-pay"})
   @ApiOperation("提交付款")
   public AjaxResult commitPay(@RequestBody @Valid DrpComeAndGoCommitPayDTO content) {
      this.drpSupplierComeGoService.commitPay(content);
      return  success();
   }

   @PostMapping({"/apply-refund"})
   @ApiOperation("申请退款")
   public AjaxResult applyRefund(@RequestBody @Valid DrpComeAndGoCommitRefundApplyDTO content) {
      this.drpSupplierComeGoService.applyRefund(content);
      return  success();
   }

   @PostMapping({"/commit-refund"})
   @ApiOperation("提交退款")
   public AjaxResult commitRefund(@RequestBody @Valid DrpComeAndGoCommitRefundDTO content) {
      this.drpSupplierComeGoService.commitRefund(content);
      return  success();
   }

}
