package com.neusoft.smart.pos.inventory.controller;

import com.neusoft.smart.pos.dto.inventory.request.PostInventoryStoreBatchRequest;
import com.neusoft.smart.pos.dto.inventory.request.PutInventoryStoreBatchRequest;
import com.neusoft.smart.pos.dto.inventory.response.PostInventoryStoreBatchResponse;
import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.inventory.constants.InventoryConstant;
import com.neusoft.smart.pos.inventory.service.InventoryStoreBatchService;
import com.neusoft.smart.pos.inventory.service.InventoryStoreInoutService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "库存批次接口", description = "库存批次接口")
@RequestMapping(path = "/inventory")
@Validated
public class InventoryStoreBatchController {
    
    @Autowired
    InventoryStoreBatchService inventoryStoreBatchService;
    
    @Autowired
    InventoryStoreInoutService inventoryStoreInoutService;
    
    @ApiOperation(value = "库存批次进货接口")
    @PostMapping("/stockIn")
    public ResponseData<PostInventoryStoreBatchResponse> stockIn(@RequestBody PostInventoryStoreBatchRequest request) {
        return new ResponseData<>(inventoryStoreBatchService.increaseInventory(request, InventoryConstant.STOCK_ADD, InventoryConstant.STOCK_IN));
    }
    
    
    @ApiOperation(value = "用户退货入库接口")
    @PostMapping("/userReturn")
    public ResponseData<PostInventoryStoreBatchResponse> userReturn(@RequestBody PostInventoryStoreBatchRequest request) {
        inventoryStoreBatchService.bindGoodsInfoForRequest(request);
        inventoryStoreBatchService.bindPriceForRequest(request);
        return new ResponseData<>(inventoryStoreBatchService.increaseInventory(request, InventoryConstant.STOCK_ADD, InventoryConstant.USER_RETURN));
    }
    
    @ApiOperation(value = "盘盈入库接口")
    @PostMapping("/checkAdd")
    public ResponseData<PostInventoryStoreBatchResponse> checkAdd(@RequestBody PostInventoryStoreBatchRequest request) {
        inventoryStoreBatchService.bindGoodsInfoForRequest(request);
        return new ResponseData<>(inventoryStoreBatchService.increaseInventory(request, InventoryConstant.STOCK_ADD, InventoryConstant.CHECK_ADD));
    }
    
    @ApiOperation(value = "商品销售出库接口")
    @PutMapping("/goodsSale")
    public ResponseData<PostInventoryStoreBatchResponse> goodsSale(@RequestBody PutInventoryStoreBatchRequest request) {
        return new ResponseData<>(inventoryStoreBatchService.reduceInventory(request, InventoryConstant.STOCK_DEC, InventoryConstant.GOODS_SALE));
    }
    
    @ApiOperation(value = "商品领用出库接口")
    @PutMapping("/goodsTake")
    public ResponseData<PostInventoryStoreBatchResponse> goodsTake(@RequestBody PutInventoryStoreBatchRequest request) {
        return new ResponseData<>(inventoryStoreBatchService.reduceInventory(request, InventoryConstant.STOCK_DEC, InventoryConstant.GOODS_TAKE));
    }
    
    @ApiOperation(value = "盘损出库接口")
    @PutMapping("/checkDec")
    public ResponseData<PostInventoryStoreBatchResponse> checkDec(@RequestBody PutInventoryStoreBatchRequest request) {
        return new ResponseData<>(inventoryStoreBatchService.reduceInventory(request, InventoryConstant.STOCK_DEC, InventoryConstant.CHECK_DEC));
    }
    
    @ApiOperation(value = "向供应商退货出库接口")
    @PutMapping("/supReturn")
    public ResponseData<PostInventoryStoreBatchResponse> supReturn(@RequestBody PutInventoryStoreBatchRequest request) {
        return new ResponseData<>(inventoryStoreBatchService.reduceInventory(request, InventoryConstant.STOCK_DEC, InventoryConstant.SUP_RETURN));
    }
}
