package com.bonus.material.devConfig.controller;

import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.material.devConfig.domain.EquipmentProperty;
import com.bonus.material.devConfig.domain.EquipmentPropertyDTO;
import com.bonus.material.devConfig.service.EquipmentPropertyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 装备特征值管理
 */
@RestController
@RequestMapping("/equipment/property")
public class EquipmentPropertyController {

    @Autowired
    private EquipmentPropertyService equipmentPropertyService;

    /**
     * 查询特征值列表
     */
    @GetMapping("/list")
    public AjaxResult list() {
        List<EquipmentProperty> list = equipmentPropertyService.list();

        return AjaxResult.success(list);
    }

    /**
     * 根据ID查询特征值
     */
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        EquipmentProperty property = equipmentPropertyService.getById(id);
        return AjaxResult.success(property);
    }

    /**
     * 根据类型ID查询特征值
     */
    @GetMapping("/type/{typeId}")
    public AjaxResult getByTypeId(@PathVariable Long typeId) {
        List<EquipmentProperty> properties = equipmentPropertyService.getByTypeId(typeId);
        return AjaxResult.success(properties);
    }


    /**
     * 根据类型ID查询特征值
     */
    @GetMapping("/getByType/{typeId}")
    public AjaxResult getByType(@PathVariable Long typeId) {
        List<EquipmentProperty> properties = equipmentPropertyService.getByType(typeId);
        return AjaxResult.success(properties);
    }

    /**
     * 根据类型ID查询特征项名称(去重)
     */
    @GetMapping("/type/name/{typeId}")
    public AjaxResult getNameByTypeId(@PathVariable Long typeId) {
        List<EquipmentProperty> properties = equipmentPropertyService.getNameByTypeId(typeId);
        return AjaxResult.success(properties);
    }

    /**
     * 根据类型ID查询装备类型及其特征值（扁平化结果）
     */
    @GetMapping("/type-with-properties/{typeId}")
    public AjaxResult getTypeWithProperties(@PathVariable Long typeId) {
        List<EquipmentPropertyDTO> result = equipmentPropertyService.getTypeWithProperties(typeId);
        return AjaxResult.success(result);
    }

    /**
     * 查询所有装备类型及其特征值（扁平化结果）
     */
    @GetMapping("/all-types-with-properties")
    public AjaxResult getAllTypesWithProperties() {
        List<EquipmentPropertyDTO> result = equipmentPropertyService.getAllTypesWithProperties();
        return AjaxResult.success(result);
    }

    /**
     * 查询装备类型详情及其特征值列表（嵌套结构）
     */
    @GetMapping("/type-detail-with-properties/{typeId}")
    public AjaxResult getTypeDetailWithProperties(@PathVariable Long typeId) {
        EquipmentPropertyDTO result = equipmentPropertyService.getTypeDetailWithProperties(typeId);
        return AjaxResult.success(result);
    }

    /**
     * 新增特征值
     */
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody EquipmentProperty equipmentProperty) {
        equipmentPropertyService.add(equipmentProperty);
        return AjaxResult.success();
    }

    /**
     * 修改特征值
     */
    @PutMapping("/update")
    public AjaxResult update(@Validated @RequestBody EquipmentProperty equipmentProperty) {
        equipmentPropertyService.update(equipmentProperty);
        return AjaxResult.success();
    }

    /**
     * 删除特征值
     */
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        equipmentPropertyService.delete(id);
        return AjaxResult.success();
    }
}