package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.device.entity.DeviceConfigEntity;
import com.ycwl.basic.model.pc.device.req.DeviceAddOrUpdateReq;
import com.ycwl.basic.model.pc.device.req.DeviceBatchSortRequest;
import com.ycwl.basic.model.pc.device.req.DeviceReqQuery;
import com.ycwl.basic.model.pc.device.req.DeviceSortRequest;
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
import com.ycwl.basic.model.pc.template.req.TemplateSortRequest;
import com.ycwl.basic.service.pc.DeviceService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：longbinbin
 * @Date：2024/12/2 16:13
 */
@RestController
@RequestMapping("/api/device/v1")
@Api(tags = "设备管理")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @ApiOperation("设备分页查询")
    @PostMapping("/page")
    public ApiResponse<PageInfo<DeviceRespVO>> pageQuery(@RequestBody DeviceReqQuery deviceReqQuery) {
        return deviceService.pageQuery(deviceReqQuery);
    }
    @ApiOperation("设备列表查询")
    @PostMapping("/list")
    public ApiResponse list(@RequestBody DeviceReqQuery deviceReqQuery) {
        return deviceService.list(deviceReqQuery);
    }
    @ApiOperation("设备详情查询")
    @GetMapping("/getDetails/{id}")
    public ApiResponse<DeviceRespVO> getDetails(@PathVariable("id") Long id) {
        return deviceService.getById(id);
    }
    @ApiOperation("新增或修改设备")
    @PostMapping("/addOrUpdate")
    public ApiResponse addOrUpdate(@RequestBody DeviceAddOrUpdateReq deviceReqQuery) {
        return deviceService.addOrUpdate(deviceReqQuery);
    }
    @ApiOperation("删除设备")
    @DeleteMapping("/delete/{id}")
    public ApiResponse delete(@PathVariable("id") Long id) {
        return deviceService.deleteById(id);
    }
    @ApiOperation("修改设备状态")
    @PutMapping("/updateStatus/{id}")
    public ApiResponse updateStatus(@PathVariable("id") Long id) {
        return deviceService.updateStatus(id);
    }

    @ApiOperation("排序设备")
    @PostMapping("/sort")
    public ApiResponse<Boolean> sortDevice(@RequestBody DeviceSortRequest request) {
        return deviceService.sortDevice(request.getDeviceId(), request.getAfterDeviceId());
    }

    @PostMapping("/scenic/{scenicId}/sortBatch")
    public ApiResponse<Boolean> sortDeviceBatch(@PathVariable("scenicId") Long scenicId, @RequestBody DeviceBatchSortRequest request) {
        return deviceService.batchSort(scenicId, request);
    }

    @GetMapping("/config/{id}")
    public ApiResponse<DeviceConfigEntity> getConfig(@PathVariable("id") Long id) {
        return ApiResponse.success(deviceService.getConfig(id));
    }

    @PostMapping("/saveConfig/{configId}")
    public ApiResponse saveConfig(@PathVariable("configId") Long configId, @RequestBody DeviceConfigEntity deviceConfigEntity) {
        deviceService.saveConfig(configId, deviceConfigEntity);
        return ApiResponse.success(null);
    }
}
