package com.fuyuanshen.equipment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.domain.ResponseVO;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
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 TableDataInfo<DeviceType> queryDeviceType(DeviceTypeQueryCriteria criteria) {
        Page<DeviceType> page = new Page<>(criteria.getPageNum(), criteria.getPageSize());
        return deviceTypeService.queryAll(criteria, page);
    }


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


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


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


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


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

    }

}
