package net.lab1024.sa.admin.module.business.wms.shipping.pick.controller;

import net.lab1024.sa.admin.module.business.wms.shipping.pick.domain.entity.PickEntity;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.domain.form.PickAddForm;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.domain.form.PickQueryForm;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.domain.form.PickUpdateForm;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.domain.vo.PickVO;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.service.PickQueryService;
import net.lab1024.sa.admin.module.business.wms.shipping.pick.service.PickService;
import net.lab1024.sa.base.common.domain.RequestUser;
import net.lab1024.sa.base.common.domain.ValidateList;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.springframework.web.bind.annotation.*;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

/**
 * 出库单 Controller
 *
 * @Author 霍锦
 * @Date 2024-12-26 15:42:11
 * @Copyright 友仓
 */

@RestController
@Tag(name = "出库单")
public class PickController {

    @Resource
    private PickService pickService;

    @Resource
    private PickQueryService pickQueryService;

    @Operation(summary = "分页查询 @author 霍锦")
    @PostMapping("/pick/queryPage")
    @SaCheckPermission("pick:query")
    public ResponseDTO<PageResult<PickVO>> queryPage(@RequestBody @Valid PickQueryForm queryForm) {
        return ResponseDTO.ok(pickQueryService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author 霍锦")
    @PostMapping("/pick/add")
    @SaCheckPermission("pick:add")
    public ResponseDTO<PickEntity> add(@RequestBody @Valid PickAddForm addForm) {
        RequestUser requestUser = SmartRequestUtil.getRequestUser();
        addForm.setCreateUserId(requestUser.getUserId());
        addForm.setCreateUserName(requestUser.getUserName());
        return pickService.add(addForm);
    }

    @Operation(summary = "更新 @author 霍锦")
    @PostMapping("/pick/update")
    @SaCheckPermission("pick:update")
    public ResponseDTO<PickEntity> update(@RequestBody @Valid PickUpdateForm updateForm) {
        return pickService.update(updateForm);
    }

    @Operation(summary = "批量删除 @author 霍锦")
    @PostMapping("/pick/batchDelete")
    @SaCheckPermission("pick:batchDelete")
    public ResponseDTO<String> batchDelete(@RequestBody ValidateList<Long> idList) {
        return pickService.batchDelete(idList);
    }

    @Operation(summary = "单个删除 @author 霍锦")
    @GetMapping("/pick/delete")
    @SaCheckPermission("pick:delete")
    public ResponseDTO<String> delete(@RequestParam Long pickId) {
        return pickService.delete(pickId);
    }
}
