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.context.LoginUserInfo;
import com.cool.store.request.config.ConfigItemQueryRequest;
import com.cool.store.request.config.ConfigItemUpdateRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.config.ConfigItemService;
import com.cool.store.vo.config.ConfigItemVO;
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/configItem")
@RequiredArgsConstructor
public class ConfigItemController {

    private final ConfigItemService configItemService;

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

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

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

    @ApiOperation("查询大类下的配置项")
    @GetMapping("/listByCategoryId")
    public ResponseResult<List<ConfigItemVO>> listByCategoryId(@RequestParam("CategoryId") Long CategoryId) {
        return ResponseResult.success(configItemService.listByCategoryId(CategoryId));
    }

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