package com.fizz.business.controller;

import com.fizz.business.constants.enums.DeviceEnum;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/deviceEnum")
@Tag(name = "设备枚举")
@Anonymous
public class DeviceEnumController {

    @GetMapping("/all")
    @Operation(description = "获取DeviceEnum全量定义（用于前端动态渲染）")
    public R<List<DeviceDefVO>> all() {
        List<DeviceDefVO> list = Arrays.stream(DeviceEnum.values())
                .map(DeviceDefVO::from)
                .collect(Collectors.toList());
        return R.ok(list);
    }

    @Data
    public static class DeviceDefVO {
        private String deviceCode; // DeviceEnum.name()
        private Integer idx;
        private String desc;
        private Double basePosition;
        private String sectionType;
        private String sourceType;
        private List<String> paramFields;

        public static DeviceDefVO from(DeviceEnum e) {
            DeviceDefVO vo = new DeviceDefVO();
            vo.setDeviceCode(e.name());
            vo.setIdx(e.getIdx());
            vo.setDesc(e.getDesc());
            vo.setBasePosition(e.getBasePosition());
            vo.setSectionType(e.getSectionType().name());
            vo.setSourceType(e.getSourceType().name());
            vo.setParamFields(e.getParamFields());
            return vo;
        }
    }
}

