package com.fuyuanshen.equipment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.PageResult;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.equipment.domain.DeviceType;
import com.fuyuanshen.equipment.domain.form.DeviceTypeForm;
import com.fuyuanshen.equipment.domain.query.DeviceTypeQueryCriteria;
import com.fuyuanshen.equipment.service.DeviceTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: WY
 * @Date: 2025/5/13
 **/
@Tag(name = "设备类型管理", description = "设备类型管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/deviceType")
public class DeviceTypeController {

    private final DeviceTypeService deviceTypeService;


    @GetMapping
    @Operation(summary = "分页查询设备类型")
    public ResponseVO<PageResult<DeviceType>> queryDeviceType(DeviceTypeQueryCriteria criteria) {
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return ResponseVO.success(deviceTypeService.queryAll(criteria, page));
    }


    @GetMapping(value = "/all")
    @Operation(summary = "查询所有设备类型")
    public ResponseVO<Object> queryDeviceTypes() {
        List<DeviceType> deviceTypes = deviceTypeService.queryDeviceTypes();
        return ResponseVO.success(deviceTypes);
    }


    // @Log("新增设备类型")
    @Operation(summary = "新增设备类型")
    @PostMapping(value = "/add")
    public ResponseVO<Object> createDeviceType(@Validated @RequestBody DeviceType resources) {
        deviceTypeService.create(resources);
        return ResponseVO.success(null);
    }


    // @Log("修改设备类型")
    @Operation(summary = "修改设备类型")
    @PutMapping(value = "/update")
    public ResponseVO<Object> updateDeviceType(@Validated @RequestBody DeviceTypeForm resources) {
        deviceTypeService.update(resources);
        return ResponseVO.success(null);
    }


    // @Log("删除设备类型")
    @Operation(summary = "删除设备类型")
    @DeleteMapping(value = "/delete")
    public ResponseVO<Object> deleteDeviceType(@Parameter(name = "传ID数组[]") @RequestBody List<Long> ids) {
        deviceTypeService.deleteAll(ids);
        return ResponseVO.success("删除成功!!!");
    }


    @GetMapping(value = "/communicationMode")
    @Operation(summary = "获取设备类型通讯方式")
    public ResponseVO<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
        return ResponseVO.success(deviceTypeService.getCommunicationMode(id));
    }

}
