package org.wcs.serve.controller.app;

import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wcs.model.dto.serve.plc.AddPlcReq;
import org.wcs.model.dto.serve.plc.QueryBasePlcReq;
import org.wcs.model.dto.serve.plc.UpdatePlcReq;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.AppServeResponse;
import org.wcs.model.vo.serve.plc.QueryBasePlcResp;
import org.wcs.serve.service.intf.IPlcService;

import java.util.List;

/**
 * plc 相关控制器
 */
@RestController
@RequestMapping("/app/plc")
@ResponseBody
@RequiredArgsConstructor
public class PlcController {

    private final IPlcService plcService;

    /**
     * 查询 plc
     * @param queryPlcReq 查询 plc 请求
     * @return 查询结果
     */
    @PostMapping("/queryBasePlc")
    public AppServeDataResponse<List<QueryBasePlcResp>> queryPlc(@RequestBody QueryBasePlcReq queryPlcReq) {
        return plcService.queryPlc(queryPlcReq);
    }

    /**
     * 新增 plc
     * @param addPlcReq 新增 plc 请求
     * @return 新增结果
     */
    @PostMapping("/addPlc")
    public AppServeResponse addPlc(@RequestBody @Validated AddPlcReq addPlcReq) {
        return plcService.addPlc(addPlcReq);
    }

    /**
     * 修改 plc
     * @param updatePlcReq 修改 plc 请求
     * @return 修改结果
     */
    @PostMapping("/updatePlc")
    public AppServeResponse updatePlc(@RequestBody @Validated UpdatePlcReq updatePlcReq) {
        return plcService.updatePlc(updatePlcReq);
    }

    /**
     * 删除 plc
     * @param plcId plcId
     * @return 删除结果
     */
    @DeleteMapping("/deletePlc/{plcId}")
    public AppServeResponse deletePlc(@PathVariable @NotNull(message = "plcId不能为空") Integer plcId) {
        return plcService.deletePlc(plcId);
    }



}
