package com.ruoyi.custclient.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.custclient.dto.QueryLabelCodeDto;
import com.ruoyi.custclient.dto.QueryLabelTypeDto;
import com.ruoyi.custclient.dto.SaveLabelDto;
import com.ruoyi.custclient.service.LabelService;
import com.ruoyi.custclient.vo.PageLabelCodeVo;
import com.ruoyi.custclient.vo.PageLabelTypeVO;
import com.ruoyi.system.domain.LabelCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/label")
public class LabelController extends BaseController {

    @Autowired
    private LabelService labelService;

    // 获取标签列表 分页
    @PostMapping("/getLabelCodeInPage")
    public AjaxResult getLabelCodeInPage(@RequestBody QueryLabelCodeDto dto) {
        Page<PageLabelCodeVo> vos = labelService.getLabelCodeInPage(dto);
        return AjaxResult.success(vos);
    }


    // 保存 标签组 标签
    @PostMapping("/saveLabel")
    public AjaxResult saveLabel(@RequestBody SaveLabelDto dto) {
        boolean save = labelService.saveLabel(dto);
        return AjaxResult.checkBool(save);
    }

    // 获取标签组列表 分页
    @PostMapping("/getLabelTypeInPage")
    private TableDataInfo getLabelTypeInPage(@RequestBody QueryLabelTypeDto dto) {
        List<PageLabelTypeVO> vos = labelService.getLabelTypeInPage(dto);
        return getDataTable(vos);
    }

    // 获取标签list
    @GetMapping("/getLabelCodeList")
    public AjaxResult getLabelCodeList() {
        List<LabelCode> vos = labelService.getLabelCodeList();
        return AjaxResult.success(vos);
    }


    //删除标签组
    @GetMapping("/delLabelType")
    public AjaxResult delLabelType(Long labelTypeId) {
        boolean b = labelService.removeLabelTypeById(labelTypeId);
        return AjaxResult.checkBool(b);
    }

}
