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

import com.bonus.canteen.core.supply.purchase.domain.param.DrpContractCommitDTO;
import com.bonus.canteen.core.supply.purchase.domain.param.DrpContractPageDTO;
import com.bonus.canteen.core.supply.purchase.domain.vo.DrpContractPageVO;
import com.bonus.canteen.core.supply.purchase.service.DrpProcurementContractService;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping({"/api/v1/drpProcurementContract"})
@Api(
   value = "ffc-采购合同主表",
   tags = {"ffc-采购合同主表"}
)
public class DrpProcurementContractController extends BaseController {
   private static final Logger log = LoggerFactory.getLogger(DrpProcurementContractController.class);
   @Autowired
   @Lazy
   private DrpProcurementContractService drpProcurementContractService;

   @PostMapping({"/commit"})
   @ApiOperation("新增合同")
   public AjaxResult commit(@RequestBody @Valid DrpContractCommitDTO request) {
      this.drpProcurementContractService.commit(request);
      return AjaxResult.success();
   }

   @PostMapping({"/page"})
   @ApiOperation("分页查询合同")
   public TableDataInfo page(@RequestBody @Valid DrpContractPageDTO request) {
      startPage();
      return getDataTable(this.drpProcurementContractService.page(request));
   }

   @PostMapping({"/detail/{contractId}"})
   @ApiOperation("合同详情")
   public AjaxResult detail(@PathVariable("contractId") String contractId) {
      return AjaxResult.success(this.drpProcurementContractService.detail(contractId));
   }

   @PostMapping({"/remove/{contractId}"})
   @ApiOperation("删除合同")
   public AjaxResult remove(@PathVariable("contractId") String contractId) {
      this.drpProcurementContractService.remove(contractId);
      return AjaxResult.success();
   }

   @PostMapping({"/close/{contractId}"})
   @ApiOperation("终止合同")
   public AjaxResult close(@PathVariable("contractId") String contractId) {
      this.drpProcurementContractService.close(contractId);
      return AjaxResult.success();
   }
}
