package com.dayou.controller;

import com.dayou.bo.HeadlineTreeBO;
import com.dayou.common.CascaderDTO;
import com.dayou.vo.IdNameVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RestController;
import com.dayou.service.IReportHeadlineService;
import com.dayou.entity.ReportHeadline;
import com.dayou.common.RestResponse;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * 报告标题
 *
 * @author wucl
 * @since 2023-08-09
 */
@RestController
@RequestMapping("reportHeadline")
@Slf4j
public class ReportHeadlineController extends BaseController {
    @Autowired
    private IReportHeadlineService reportHeadlineService;

    /**
    * 报告标题列表
    */
    @GetMapping("")
    public RestResponse<Page<ReportHeadline>> page(ReportHeadline reportHeadline, Page page){
        Page<ReportHeadline> pages=reportHeadlineService.selectPage(page,reportHeadline);
        return RestResponse.data(pages);
    }

    /**
     * 报告标题详情
     */
    @GetMapping("/{id}")
    public RestResponse<ReportHeadline> detail(@PathVariable Long id){
        ReportHeadline xReportHeadline =reportHeadlineService.detail(id);
        return RestResponse.data(xReportHeadline);
     }

    /**
     * 报告标题新增
     */
    @PostMapping("")
    public RestResponse<Boolean> save(@RequestBody ReportHeadline reportHeadline) {
        Boolean ret = reportHeadlineService.add(reportHeadline);
        return RestResponse.data(ret);
    }

    /**
     * 报告标题更新
     */
    @PutMapping("")
    public RestResponse<Boolean> update(@RequestBody ReportHeadline reportHeadline) {
        Boolean ret = reportHeadlineService.update(reportHeadline);
        return RestResponse.data(ret);
    }

    /**
     * 报告标题删除
     */
    @DeleteMapping("/{id}")
    public RestResponse<Boolean> delete(@PathVariable Long id) {
        Boolean ret = reportHeadlineService.delete(id);
        return RestResponse.data(ret);
    }

    /**
     * 获取报告标题树
     * @param id
     * @return
     */
    @GetMapping("/tree/{id}")
    public RestResponse<List<HeadlineTreeBO>> getHeadlineTree(@PathVariable("id") Long id){
        List<HeadlineTreeBO> tree = reportHeadlineService.getHeadlineTree(id);
        return RestResponse.data(tree);
    }

    /**
     * 获取根标题（模板类型）
     * @return
     */
    @GetMapping("/root")
    public RestResponse<List<ReportHeadline>> getHeadlineRoot(){
        List<ReportHeadline> roots = reportHeadlineService.getHeadlineRoot();
        return RestResponse.data(roots);
    }

    /**
     * 获取全部报告标题树
     * @return
     */
    @GetMapping("/tree")
    public RestResponse<List<CascaderDTO>> getAllHeadlineTree(){
        List<CascaderDTO> trees = reportHeadlineService.getAllHeadlineTree();
        return RestResponse.data(trees);
    }
}

