package com.cool.store.controller.webb;

import com.cool.store.common.InsertGroup;
import com.cool.store.common.UpdateGroup;
import com.cool.store.request.tp.TpPenaltyRuleUpdateRequest;
import com.cool.store.request.tp.TpRewardRuleUpdateRequest;
import com.cool.store.request.tp.TpRuleEnableRequest;
import com.cool.store.request.tp.TpRuleQueryRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.tp.TpRuleService;
import com.cool.store.vo.tp.TpPenaltyRuleDetailVO;
import com.cool.store.vo.tp.TpPenaltyRuleListVO;
import com.cool.store.vo.tp.TpRewardRuleDetailVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 十二分制-奖惩规则 前端控制器
 * </p>
 *
 * @author wangff
 * @since 2025/11/4
 */
@Api(tags = "十二分制-奖惩规则")
@RestController
@RequestMapping("/pc/tp/rule")
@RequiredArgsConstructor
public class TpRuleController {
    private final TpRuleService tpRuleService;

    @ApiOperation("新增惩处规则")
    @PostMapping("/insertPenalty")
    public ResponseResult<Boolean> insertPenaltyRule(@RequestBody @Validated(InsertGroup.class) TpPenaltyRuleUpdateRequest request) {
        return ResponseResult.success(tpRuleService.insertPenaltyRule(request));
    }

    @ApiOperation("修改惩处规则")
    @PostMapping("/updatePenalty")
    public ResponseResult<Boolean> updatePenaltyRule(@RequestBody @Validated(UpdateGroup.class) TpPenaltyRuleUpdateRequest request) {
        return ResponseResult.success(tpRuleService.updatePenaltyRule(request));
    }

    @ApiOperation("惩处规则详情")
    @GetMapping("/penaltyDetail")
    @ApiImplicitParam(name = "ruleId", value = "规则id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<TpPenaltyRuleDetailVO> penaltyRuleDetail(@NotNull(message = "规则id不能为空") Long ruleId) {
        return ResponseResult.success(tpRuleService.penaltyRuleDetail(ruleId));
    }

    @ApiOperation("惩处规则分页查询")
    @PostMapping("/penaltyPage")
    public ResponseResult<PageInfo<TpPenaltyRuleListVO>> penaltyRulePage(@RequestBody TpRuleQueryRequest request) {
        request.setType(0);
        return ResponseResult.success(tpRuleService.penaltyRulePage(request));
    }

    @ApiOperation("新增加分规则")
    @PostMapping("/insertReward")
    public ResponseResult<Boolean> insertRewardRule(@RequestBody @Validated(InsertGroup.class) TpRewardRuleUpdateRequest request) {
        return ResponseResult.success(tpRuleService.insertRewardRule(request));
    }

    @ApiOperation("修改加分规则")
    @PostMapping("/updateReward")
    public ResponseResult<Boolean> updateRewardRule(@RequestBody @Validated(UpdateGroup.class) TpRewardRuleUpdateRequest request) {
        return ResponseResult.success(tpRuleService.updateRewardRule(request));
    }

    @ApiOperation("加分规则详情")
    @GetMapping("/rewardDetail")
    @ApiImplicitParam(name = "ruleId", value = "规则id", required = true, dataType = "Long", paramType = "query")
    public ResponseResult<TpRewardRuleDetailVO> rewardRuleDetail(@NotNull(message = "规则id不能为空") Long ruleId) {
        return ResponseResult.success(tpRuleService.rewardRuleDetail(ruleId));
    }

    @ApiOperation("加分规则分页查询")
    @PostMapping("/rewardPage")
    public ResponseResult<PageInfo<TpRewardRuleDetailVO>> rewardRulePage(@RequestBody TpRuleQueryRequest request) {
        request.setType(1);
        return ResponseResult.success(tpRuleService.rewardRulePage(request));
    }

    @ApiOperation("批量删除规则")
    @PostMapping("/delete")
    public ResponseResult<Boolean> deleteRuleByIds(@RequestBody List<Long> ruleIds) {
        return ResponseResult.success(tpRuleService.deleteRuleByIds(ruleIds));
    }

    @ApiOperation("启用规则")
    @PostMapping("/enable")
    public ResponseResult<Boolean> enableRuleByIds(@RequestBody @Validated TpRuleEnableRequest request) {
        return ResponseResult.success(tpRuleService.enableRuleByIds(request.getRuleIds(), request.getStatus()));
    }
}
