package jnpf.personnels.controller.web.goods;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsReceiveAddDTO;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsReceiveQueryDTO;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsReceiveReturnDTO;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsReceiveUpdateDTO;
import jnpf.model.personnels.vo.goods.FtbPersonnelsGoodsPageVO;
import jnpf.model.personnels.vo.goods.FtbPersonnelsGoodsReceiveDetailsVO;
import jnpf.model.personnels.vo.goods.FtbPersonnelsGoodsReceivePageVO;
import jnpf.personnels.service.FtbPersonnelsGoodsReceiveService;
import org.springframework.web.bind.annotation.*;

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

/**
 * web物品领用模块
 *
 * @author wangchunxiang
 * @date 2025/09/11
 */
@RestController
@RequestMapping(value = "/web/personnels-goods-receive")
public class FtbPersonnelsGoodsReceiveController {

    @Resource
    private FtbPersonnelsGoodsReceiveService ftbPersonnelsGoodsReceivesService;

    /**
     * 添加物品领用
     */
    @PostMapping(value = "/add")
    public ActionResult<Void> add(@RequestBody @Valid List<FtbPersonnelsGoodsReceiveAddDTO> form) {
        ftbPersonnelsGoodsReceivesService.create(form);
        return ActionResult.success();
    }

    /**
     * 修改物品领用
     */
    @PostMapping(value = "/update")
    public ActionResult<Void> update(@RequestBody @Valid FtbPersonnelsGoodsReceiveUpdateDTO form) {
        ftbPersonnelsGoodsReceivesService.update(form);
        return ActionResult.success();
    }

    /**
     * 删除物品领用
     *
     * @param id 物品主键id
     * @return {@link ActionResult }<{@link Void }>
     */
    @DeleteMapping(value = "/delete/{id}")
    public ActionResult<Void> delete(@PathVariable(value = "id") String id) {
        ftbPersonnelsGoodsReceivesService.delete(id);
        return ActionResult.success();
    }

    /**
     * 获取物品领用列表
     */
    @GetMapping(value = "/list")
    public ActionResult<PageListVO<FtbPersonnelsGoodsReceivePageVO>> list(FtbPersonnelsGoodsReceiveQueryDTO formQueryDTO, CultivatePage cultivatePage) {
        Page<FtbPersonnelsGoodsReceivePageVO> page = cultivatePage.coverCultivatePage();
        page = ftbPersonnelsGoodsReceivesService.list(page, formQueryDTO);
        PageListVO<FtbPersonnelsGoodsReceivePageVO> pageListVO = CultivatePage.coverPageList(page);
        return ActionResult.success(pageListVO);
    }

    /**
     * 根据物品领用主键Id获取物品领用详情
     *
     * @param id 物品领用主键Id
     * @return {@link ActionResult }<{@link FtbPersonnelsGoodsPageVO }>
     */
    @GetMapping(value = "/details")
    public ActionResult<FtbPersonnelsGoodsReceiveDetailsVO> details(@RequestParam(value = "id") String id) {
        FtbPersonnelsGoodsReceiveDetailsVO ftbPersonnelsGoodsPageVO = ftbPersonnelsGoodsReceivesService.details(id);
        return ActionResult.success(ftbPersonnelsGoodsPageVO);
    }

    /**
     * 归还物品
     */
    @PostMapping(value = "/return-goods")
    public ActionResult<Void> returnGoods(@RequestBody @Valid FtbPersonnelsGoodsReceiveReturnDTO returnDTO) {
        ftbPersonnelsGoodsReceivesService.returnGoods(returnDTO);
        return ActionResult.success();
    }

}
