package com.cool.store.controller.webb;

import com.cool.store.dto.label.LabelGroupAddDTO;
import com.cool.store.dto.label.LabelGroupDeleteDTO;
import com.cool.store.dto.label.LabelGroupListDTO;
import com.cool.store.dto.label.LabelGroupUpdateDTO;
import com.cool.store.exception.ApiException;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.LabelGroupService;
import com.cool.store.vo.LabelGroupListVo;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Fun Li 2023/8/10 10:54
 * @version 1.0
 */
@Api(tags = {"标签组管理"})
@RestController
@RequestMapping({"pc/labelGroup"})
public class LabelGroupController {
    @Autowired
    private LabelGroupService labelGroupService;

    @ApiOperation("标签组分页查询")
    @PostMapping({"/list"})
    public ResponseResult<PageInfo<LabelGroupListVo>> getLabelGroupList(@RequestBody LabelGroupListDTO dto) {
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<LabelGroupListVo> result = labelGroupService.getLabelGroupList(dto);
        return ResponseResult.success(new PageInfo<>(result));
    }

    @ApiOperation("新增标签组")
    @PostMapping({"/add"})
    public ResponseResult addLabelGroup(@RequestBody LabelGroupAddDTO dto) throws ApiException {
        labelGroupService.addLabelGroup(dto);
        return ResponseResult.success();
    }

    @ApiOperation("修改标签组")
    @PostMapping({"/edit"})
    public ResponseResult updateLabelGroup(@RequestBody LabelGroupUpdateDTO dto) throws ApiException {
        labelGroupService.updateLabelGroup(dto);
        return ResponseResult.success();
    }

    @ApiOperation("删除标签组")
    @PostMapping({"/delete"})
    public ResponseResult deleteLabelGroup(@RequestBody LabelGroupDeleteDTO dto) throws ApiException {
        labelGroupService.deleteLabelGroup(dto);
        return ResponseResult.success();
    }

    @ApiOperation("获取所有标签组")
    @PostMapping({"/allList"})
    public ResponseResult<List<LabelGroupListVo>> deleteLabelGroup() {
        return ResponseResult.success(labelGroupService.getAllLabelGroupList());
    }

    @ApiOperation("获取所有标签组")
    @PostMapping({"/allListAsc"})
    public ResponseResult<List<LabelGroupListVo>> getLabelGroupListOrder() {
        return ResponseResult.success(labelGroupService.getLabelGroupListOrder());
    }
}

