package com.cool.store.controller.webb;

import com.cool.store.dto.label.LabelAddDTO;
import com.cool.store.dto.label.LabelDeleteDTO;
import com.cool.store.dto.label.LabelListDTO;
import com.cool.store.dto.label.LabelUpdateDTO;
import com.cool.store.exception.ApiException;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.LabelService;
import com.cool.store.vo.LabelGroupVO;
import com.cool.store.vo.LabelListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Fun Li 2023/8/10 14:20
 * @version 1.0
 */
@Api(tags = "标签管理")
@RestController
@RequestMapping("pc/label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    @ApiOperation("标签列表查询")
    @PostMapping("/list")
    public ResponseResult<PageInfo<LabelListVo>> getLabelList(@RequestBody LabelListDTO dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<LabelListVo> result = labelService.getLabelList(dto);
        return ResponseResult.success(new PageInfo<>(result));
    }

    @ApiOperation("查询标签组及子标签列表")
    @GetMapping("/labelGroupAndLabelList")
    public ResponseResult<List<LabelGroupVO>> getAllLabelList() {
        List<LabelGroupVO> result = labelService.getAllGroupAndLabelList();
        return ResponseResult.success(result);
    }

    @ApiOperation("新增标签")
    @PostMapping("/add")
    public ResponseResult addLabel(@RequestBody LabelAddDTO dto) throws ApiException {
        labelService.addLabel(dto);
        return ResponseResult.success();
    }

    @ApiOperation("修改标签")
    @PostMapping("/edit")
    public ResponseResult updateLabel(@RequestBody LabelUpdateDTO dto) throws ApiException {
        labelService.updateLabel(dto);
        return ResponseResult.success();
    }

    @ApiOperation("删除标签")
    @PostMapping("/delete")
    public ResponseResult deleteLabel(@RequestBody LabelDeleteDTO dto) {
        labelService.deleteLabel(dto);
        return ResponseResult.success();
    }

}
