package net.lab1024.sa.admin.module.business.wms.receive.asn.controller;

import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.entity.AsnEntity;
import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.form.AsnAddForm;
import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.form.AsnQueryForm;
import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.form.AsnUpdateForm;
import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.vo.AsnVO;
import net.lab1024.sa.admin.module.business.wms.receive.asn.service.AsnQueryService;
import net.lab1024.sa.admin.module.business.wms.receive.asn.service.AsnService;
import net.lab1024.sa.admin.module.business.wms.receive.asn.domain.form.AsnUpdateForm;
import net.lab1024.sa.admin.module.business.wms.receive.asn.service.AsnQueryService;
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 net.lab1024.sa.base.module.support.operatelog.annotation.OperateLog;
import net.lab1024.sa.base.module.support.serialnumber.constant.SerialNumberIdEnum;
import net.lab1024.sa.base.module.support.serialnumber.service.SerialNumberService;
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 2025-03-26 15:10:02
 * @Copyright 友仓
 */

@RestController
@Tag(name = "入库单")
public class AsnController {

    @Resource
    private AsnService asnService;

    @Resource
    private AsnQueryService asnQueryService;

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

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

    @Operation(summary = "更新 @author 霍锦")
    @PostMapping("/asn/update")
    @SaCheckPermission("asn:update")
    @OperateLog
    public ResponseDTO<AsnEntity> update(@RequestBody @Valid AsnUpdateForm updateForm) {
        return asnService.update(updateForm);
    }

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

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