package com.nokia.hb.controller;

import com.nokia.common.R;
import com.nokia.hb.pojo.TreeNode;
import com.nokia.hb.pojo.dto.AddTemplateDto;
import com.nokia.hb.pojo.dto.DeleteTemplateDto;
import com.nokia.hb.pojo.dto.UpdateTemplateDto;
import com.nokia.hb.service.IndicatorTemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

@Tag(name = "指标模板")
@RestController
public class IndicatorTemplateController {
    private final IndicatorTemplateService indicatorTemplateService;

    public IndicatorTemplateController(IndicatorTemplateService indicatorTemplateService) {
        this.indicatorTemplateService = indicatorTemplateService;
    }

    /**
     * 获取指标模板
     */
    @Operation(summary = "获取指标模板")
    @PostMapping("/api/initTreeIndicatorTemplate")
    public R<List<TreeNode>> initTreeIndicatorTemplate(HttpSession session) {
        return indicatorTemplateService.initTreeIndicatorTemplate(session);
    }

    /**
     * 添加指标模板
     */
    @Operation(summary = "添加指标模板")
    @PostMapping("/api/addTemplate")
    public R<Object> addTemplate(@Valid @RequestBody AddTemplateDto dto, HttpSession session) {
        return indicatorTemplateService.addTemplate(dto, session);
    }

    /**
     * 删除指标模板
     */
    @Operation(summary = "删除指标模板")
    @PostMapping("/api/deleteTemplate")
    public R<Object> deleteTemplate(@Valid @RequestBody DeleteTemplateDto dto, HttpSession session) {
        return indicatorTemplateService.deleteTemplate(dto, session);
    }

    /**
     * 修改指标模板
     */
    @Operation(summary = "修改指标模板")
    @PostMapping("/api/updateTemplate")
    public R<Object> updateTemplate(@Valid @RequestBody UpdateTemplateDto dto, HttpSession session) {
        return indicatorTemplateService.updateTemplate(dto, session);
    }
}
