package com.cool.store.controller.webb;

import com.cool.store.common.InsertGroup;
import com.cool.store.common.UpdateGroup;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.request.config.ConfigItemCategoryQueryRequest;
import com.cool.store.request.config.ConfigItemCategoryUpdateRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.config.ConfigItemCategoryService;
import com.cool.store.vo.config.ConfigItemCategoryVO;
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/configItemCategory")
@RequiredArgsConstructor
public class ConfigItemCategoryController {

    private final ConfigItemCategoryService configItemCategoryService;

    @ApiOperation("新增配置大类")
    @PostMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody @Validated(InsertGroup.class) ConfigItemCategoryUpdateRequest request) {
        return ResponseResult.success(configItemCategoryService.add(request, CurrentUserHolder.getUser()));
    }

    @ApiOperation("编辑配置大类")
    @PostMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody @Validated(UpdateGroup.class) ConfigItemCategoryUpdateRequest request) {
        return ResponseResult.success(configItemCategoryService.update(request, CurrentUserHolder.getUser()));
    }

    @ApiOperation("分页查询配置大类")
    @PostMapping("/queryPage")
    public ResponseResult<PageInfo<ConfigItemCategoryVO>> queryPage(@RequestBody ConfigItemCategoryQueryRequest request) {
        return ResponseResult.success(configItemCategoryService.queryPage(request));
    }

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