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.FtbPersonnelsGoodsFormDTO;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsFormQueryDTO;
import jnpf.model.personnels.dto.goods.FtbPersonnelsGoodsFormUpdateDTO;
import jnpf.model.personnels.vo.goods.FtbPersonnelsGoodsPageVO;
import jnpf.personnels.service.FtbPersonnelsGoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * web物品管理模块
 *
 * @author wangchunxiang
 * @date 2025/09/11
 */
@RestController
@RequestMapping(value = "/web/personnels-goods")
public class FtbPersonnelsGoodsController {

    @Resource
    private FtbPersonnelsGoodsService ftbPersonnelsGoodsService;

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

    /**
     * 修改物品
     */
    @PostMapping(value = "/update")
    public ActionResult<Void> update(@RequestBody @Valid FtbPersonnelsGoodsFormUpdateDTO form) {
        ftbPersonnelsGoodsService.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) {
        ftbPersonnelsGoodsService.delete(id);
        return ActionResult.success();
    }

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

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

    /**
     * 删除物品二次确认
     *
     * @param id 物品主键id
     * @return {@link ActionResult }<{@link Boolean }> true为当前物品需要归还，false为当前物品不需要归还
     */
    @GetMapping(value = "/delete-confirm")
    public ActionResult<Boolean> deleteConfirm(@RequestParam(value = "id") String id) {
        Boolean deleteConfirm = ftbPersonnelsGoodsService.deleteConfirm(id);
        return ActionResult.success(deleteConfirm);
    }

}