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.TeamInviteConfig;
import top.continew.admin.business.model.query.TeamInviteConfigQuery;
import top.continew.admin.business.model.req.TeamInviteConfigReq;
import top.continew.admin.business.service.ITeamInviteConfigService;
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.model.resp.BasePageResp;

import java.util.List;

@RestController
@RequestMapping("/team/config")
@AllArgsConstructor
@Tag(name = "团队邀请配置API")
public class TeamInviteConfigController {
    private final ITeamInviteConfigService teamInviteConfigService;

    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    BasePageResp<TeamInviteConfig> page(TeamInviteConfigQuery query) {
        return teamInviteConfigService.getTeamInviteConfigPage(query);
    }


    @Operation(summary = "查询详情", description = "查询详情")
    @GetMapping("/{ids}")
    @Parameter(
            name = "ids",
            description = "ids",
            example = "1,2,3,4",
            in = ParameterIn.PATH
    )
    List<TeamInviteConfig> getInviteRewardsRuleByIds(@PathVariable("ids") List<Long> ids) {
        return teamInviteConfigService.listByIds(ids);
    }


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

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


    @Operation(
            summary = "新增数据",
            description = "新增数据"
    )
    @PostMapping
    public BaseIdResp<Long> add(@RequestBody TeamInviteConfigReq req) {
        return new BaseIdResp<>(teamInviteConfigService.addTeamInviteConfig(req));
    }
}
