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

import cn.iocoder.yudao.module.system.controller.admin.positionmap.dto.PositionChangePointBindingDTO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionChangePointBindingSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.positionmap.vo.PositionMapItemSaveReqVO;
import cn.iocoder.yudao.module.system.service.positionmap.PositionChangePointBindingService;
import cn.iocoder.yudao.module.system.service.positionmap.PositionMapItemService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import java.util.List;

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



@Tag(name = "管理后台 - 区域变更点绑定")
@RestController
@RequestMapping("/system/position-change-point-binding")
@Validated
public class PositionChangePointBindingController {

    @Resource
    private PositionChangePointBindingService positionChangePointBindingService;

    @Resource
    private PositionMapItemService positionMapItemService;

    @PostMapping("/create")
    @Operation(summary = "创建区域变更点绑定")
    @PreAuthorize("@ss.hasPermission('system:position-change-point-binding:create')")
    public CommonResult<Long> createPositionChangePointBinding(@Valid @RequestBody PositionChangePointBindingSaveReqVO createReqVO) {
        return success(positionChangePointBindingService.createPositionChangePointBinding(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新区域变更点绑定")
    @PreAuthorize("@ss.hasPermission('system:position-change-point-binding:update')")
    public CommonResult<Boolean> updatePositionChangePointBinding(@Valid @RequestBody PositionChangePointBindingSaveReqVO updateReqVO) {
        positionChangePointBindingService.updatePositionChangePointBinding(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除区域变更点绑定")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('system:position-change-point-binding:delete')")
    public CommonResult<Boolean> deletePositionChangePointBinding(@RequestParam("id") Long id) {
        positionChangePointBindingService.deletePositionChangePointBinding(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "根据点位id，查询此点位已经绑定的转换点信息")
    @Parameter(name = "id", description = "点位id", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:position-change-point-binding:query')")
    public CommonResult<PositionChangePointBindingDTO> getPositionChangePointBinding(@RequestParam("id") Long id) {
        PositionChangePointBindingDTO positionChangePointBinding = positionChangePointBindingService.getPositionChangePointBinding(id);
        return success(positionChangePointBinding);
    }

    @GetMapping("/getItemBySortNum")
    @Operation(summary = "根据排序查询点位信息(区域变更点)")
    @Parameter(name = "sortNum", description = "点位自增排序", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('system:position-change-point-binding:getItemBySortNum')")
    public CommonResult<List<PositionMapItemSaveReqVO>> getItemBySortNum(@RequestParam("sortNum") Long sortNum) {
        List<PositionMapItemSaveReqVO> positionMapItemSaveReqVO = positionMapItemService.getItemBySortNum(sortNum);
        return success(positionMapItemSaveReqVO);
    }

}