package net.lab1024.sa.admin.module.business.wms.base.area.controller;

import net.lab1024.sa.admin.module.business.wms.base.area.domain.entity.AreaEntity;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.form.AreaAddForm;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.form.AreaQueryForm;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.form.AreaSelect;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.form.AreaUpdateForm;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.vo.AreaVO;
import net.lab1024.sa.admin.module.business.wms.base.area.service.AreaQueryService;
import net.lab1024.sa.admin.module.business.wms.base.area.service.AreaService;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.form.AreaAddForm;
import net.lab1024.sa.admin.module.business.wms.base.area.domain.vo.AreaVO;
import net.lab1024.sa.admin.module.business.wms.base.area.service.AreaQueryService;
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 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;

import java.util.List;

/**
 * 库区信息 Controller
 *
 * @Author hj
 * @Date 2025-03-11 11:12:36
 * @Copyright 友仓
 */

@RestController
@Tag(name = "库区信息")
public class AreaController {

    @Resource
    private AreaQueryService areaQueryService;

    @Resource
    private AreaService areaService;

    @Operation(summary = "分页查询 @author hj")
    @PostMapping("/area/queryPage")
    @SaCheckPermission("area:query")
    public ResponseDTO<PageResult<AreaVO>> queryPage(@RequestBody @Valid AreaQueryForm queryForm) {
        return ResponseDTO.ok(areaQueryService.queryPage(queryForm));
    }

    @Operation(summary = "添加 @author hj")
    @PostMapping("/area/add")
    @SaCheckPermission("area:add")
    @OperateLog
    public ResponseDTO<String> add(@RequestBody @Valid AreaAddForm addForm) {
        RequestUser requestUser = SmartRequestUtil.getRequestUser();
        addForm.setCreateUserId(requestUser.getUserId());
        addForm.setCreateUserName(requestUser.getUserName());
        return areaService.add(addForm);
    }

    @Operation(summary = "更新 @author hj")
    @PostMapping("/area/update")
    @SaCheckPermission("area:update")
    @OperateLog
    public ResponseDTO<String> update(@RequestBody @Valid AreaUpdateForm updateForm) {
        return areaService.update(updateForm);
    }

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

    @Operation(summary = "单个删除 @author hj")
    @GetMapping("/area/delete")
    @SaCheckPermission("area:delete")
    @OperateLog
    public ResponseDTO<String> batchDelete(@RequestParam Long areaId) {
        return areaService.delete(areaId);
    }

    @Operation(summary = "库区下拉查询")
    @PostMapping("/area/queryArea")
    public ResponseDTO<List<AreaEntity>> queryArea(@RequestBody AreaSelect areaSelect) {
        return ResponseDTO.ok(areaQueryService.queryArea(areaSelect));
    }
}
