package top.continew.admin.controller.business;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.business.model.entity.InviteRewardsRule;
import top.continew.admin.business.model.query.InviteRewardsRuleQuery;
import top.continew.admin.business.model.req.InviteRewardsRuleReq;
import top.continew.admin.business.service.IInviteRewardsRuleService;
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.model.resp.BasePageResp;

import java.util.List;

@RestController
@RequestMapping("/invite/rewards/rules")
@Tag(name = "邀请用户金币奖励规则API")
@AllArgsConstructor
public class InviteRewardsRulesController {
    private final IInviteRewardsRuleService ruleService;

    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    BasePageResp<InviteRewardsRule> page(InviteRewardsRuleQuery query) {
        return ruleService.InviteRewardsRulePage(query);
    }


    @Operation(summary = "查询规则数据", description = "查询规则数据")
    @GetMapping("/{ids}")
    @Parameter(
            name = "ids",
            description = "ids",
            example = "1,2,3,4",
            in = ParameterIn.PATH
    )
    List<InviteRewardsRule> getInviteRewardsRuleByIds(@PathVariable("ids") List<Long> ids) {
        return ruleService.getByIds(ids);
    }


    @Operation(summary = "修改数据", description = "修改数据")
    @Parameter(
            name = "id",
            description = "ID",
            example = "1",
            in = ParameterIn.PATH
    )
    @PutMapping({"/{id}"})
    //@Validated({CrudValidationGroup.Update.class})
    public void update(@RequestBody InviteRewardsRuleReq req, @PathVariable("id") Long id) {
        this.ruleService.updateRules(id, req);
    }

    @Operation(
            summary = "删除数据",
            description = "删除数据"
    )
    @DeleteMapping({"/{ids}"})
    public void delete(@PathVariable("ids") List<Long> ids) {
        this.ruleService.delete(ids);
    }


    @Operation(
            summary = "新增奖励规则数据",
            description = "新增奖励规则数据"
    )
    @PostMapping
    public BaseIdResp<Long> add(@RequestBody InviteRewardsRuleReq req) {
        return new BaseIdResp<>(ruleService.addRulesByLevel(req));
    }

}
