package com.persagy.adm.diagram.controller;

import com.persagy.adm.diagram.frame.EditRequest;
import com.persagy.adm.diagram.core.model.legend.Legend;
import com.persagy.adm.diagram.manage.LegendManager;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.common.utils.ResultHelper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("legend")
public class LegendController {

	@Autowired
	private LegendManager legendManager;

	@ApiOperation("按照系统代码，查询图例列表")
	@GetMapping("getLegends")
	public CommonResult<List<Legend>> getLegends(@RequestParam String sys){
		return ResultHelper.single(legendManager.getLegends(sys));
	}

	@PostMapping("saveLegend")
	public CommonResult<Legend> saveLegend(@RequestBody EditRequest req){
		return ResultHelper.single(legendManager.saveLegend(req.getLegend(), req.getSys()));
	}

	@PostMapping("delLegend")
	public CommonResult<Boolean> delLegend(@RequestBody EditRequest req){
		return ResultHelper.single(legendManager.deleteLegend(req.getCurrentCompId(), req.getSys()));
	}

//	@RequestMapping("fixRel")
//	public CommonResult<Boolean> fixRel(){
//		return ResultHelper.single(legendManager.fixRel());
//	}

	@RequestMapping("fixDiagramType")
	public CommonResult<Boolean> fixDiagramType(){
		return ResultHelper.single(legendManager.fixDiagramType());
	}

}