package com.hys.app.controller.erp.use;

import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dto.StockInventoryDTO;
import com.hys.app.model.erp.dto.StockInventoryParam;
import com.hys.app.model.erp.vo.StockInventoryVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.StockInventoryManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

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

/**
 * 库存盘点单相关API
 *
 * @author dmy
 * 2023-12-05
 */
@Api(description = "库存盘点单相关API")
@RestController
@RequestMapping("/admin/stock/inventory")
@Validated
public class StockInventoryManagerController {

    @Autowired
    private StockInventoryManager stockInventoryManager;

    @ApiOperation(value = "查询库存盘点单分页列表数据")
    @GetMapping
    public WebPage list(StockInventoryParam params) {
        return stockInventoryManager.list(params);
    }

    @ApiOperation(value = "新增库存盘点单")
    @PostMapping
    @Log(client = LogClient.admin, detail = "新增库存盘点单")
    public void add(@RequestBody @Valid StockInventoryDTO stockInventoryDTO) {
        AdminUserContext.hasCompany();
        this.stockInventoryManager.add(stockInventoryDTO);
    }

    @ApiOperation(value = "修改库存盘点单")
    @PostMapping("/{id}")
    @Log(client = LogClient.admin, detail = "修改id为[${id}]的库存盘点单")
    public void edit(@PathVariable Long id, @RequestBody @Valid StockInventoryDTO stockInventoryDTO) {
        this.stockInventoryManager.edit(id, stockInventoryDTO);
    }

    @ApiOperation(value = "查询库存盘点单详细信息")
    @GetMapping("/{id}")
    public StockInventoryVO getDetail(@PathVariable Long id) {
        return stockInventoryManager.getDetail(id);
    }

    @ApiOperation(value = "同步库存")
    @GetMapping("/syncStock/{id}")
    public void syncStock(@PathVariable Long id) {
        stockInventoryManager.syncStock(id);
    }

    @ApiOperation(value = "删除库存盘点单")
    @DeleteMapping("/{id}")
    @Log(client = LogClient.admin, detail = "删除ID为[${id}]的库存盘点单")
    public void delete(@PathVariable Long id) {
        this.stockInventoryManager.delete(id);
    }
}
