package cn.iocoder.yudao.module.system.controller.admin.positionmap;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapLineRespVO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapLineSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.positionmap.PositionMapLineDO;
import cn.iocoder.yudao.module.system.service.positionmap.PositionMapLineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 仓库点位地图连线")
@RestController
@RequestMapping("/system/position-map-line")
@Validated
public class PositionMapLineController {

    @Resource
    private PositionMapLineService positionMapLineService;

    @PostMapping("/createOrEditOrDel")
    @Operation(summary = "创建编辑删除仓库点位地图连线")
    @PreAuthorize("@ss.hasPermission('system:position-map-line:create')")
    public CommonResult<Boolean> createOrEditOrDel(@RequestParam Long positionMapId, @Valid @RequestBody List<PositionMapLineSaveReqVO> createReqVO) {
        positionMapLineService.createOrEditPositionMapLine(positionMapId, createReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除仓库点位地图连线")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:position-map-line:delete')")
    public CommonResult<Boolean> deletePositionMapLine(@RequestParam("id") Long id) {
        positionMapLineService.deletePositionMapLine(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得仓库点位地图连线")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:position-map-line:query')")
    public CommonResult<PositionMapLineRespVO> getPositionMapLine(@RequestParam("id") Long id) {
        PositionMapLineDO positionMapLine = positionMapLineService.getPositionMapLine(id);
        return success(BeanUtils.toBean(positionMapLine, PositionMapLineRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "通过地图id获取连线列表")
    @PreAuthorize("@ss.hasPermission('system:position-map-line:query')")
    public CommonResult<List<PositionMapLineRespVO>> list(@RequestParam Long positionMapId) {
        List<PositionMapLineDO> list = positionMapLineService.getByMapId(positionMapId);
        return success(BeanUtils.toBean(list, PositionMapLineRespVO.class));
    }


}
