package com.cool.store.controller.webb;

import com.cool.store.common.InsertGroup;
import com.cool.store.common.UpdateGroup;
import com.cool.store.request.config.ConfigOptionQueryRequest;
import com.cool.store.request.config.ConfigOptionTreeQueryRequest;
import com.cool.store.request.config.ConfigOptionUpdateRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.config.ConfigOptionService;
import com.cool.store.vo.config.ConfigOptionTreeVO;
import com.cool.store.vo.config.ConfigOptionVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "标准店-配置选项管理")
@RestController
@RequestMapping("/pc/configOption")
@RequiredArgsConstructor
public class ConfigOptionController {

    private final ConfigOptionService configOptionService;

    @ApiOperation("新增配置选项")
    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody @Validated(InsertGroup.class) ConfigOptionUpdateRequest request) {
        return ResponseResult.success(configOptionService.add(request));
    }

    @ApiOperation("编辑配置选项")
    @PostMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody @Validated(UpdateGroup.class) ConfigOptionUpdateRequest request) {
        return ResponseResult.success(configOptionService.update(request));
    }

    @ApiOperation("分页查询配置选项")
    @PostMapping("/queryPage")
    public ResponseResult<PageInfo<ConfigOptionVO>> queryPage(@RequestBody ConfigOptionQueryRequest request) {
        return ResponseResult.success(configOptionService.queryPage(request));
    }

    @ApiOperation("查询激活的配置选项三层结构")
    @GetMapping("/listActiveTree")
    public ResponseResult<List<ConfigOptionTreeVO>> listActiveTree() {
        return ResponseResult.success(configOptionService.listActiveTree());
    }

    @ApiOperation("批量删除配置选项")
    @PostMapping("/deleteByIds")
    public ResponseResult<Boolean> deleteByIds(@RequestBody List<Long> ids) {
        return ResponseResult.success(configOptionService.deleteByIds(ids));
    }
}
