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.TaskInfo;
import top.continew.admin.business.model.query.TaskInfoQuery;
import top.continew.admin.business.model.req.TaskInfoReq;
import top.continew.admin.business.service.ITaskInfoService;
import top.continew.starter.extension.crud.model.resp.BaseIdResp;
import top.continew.starter.extension.crud.model.resp.BasePageResp;

import java.util.List;

@RestController
@RequestMapping("/coin/task/info")
@Tag(name = "任务信息管理api")
@AllArgsConstructor
public class TaskInfoController {

    private final ITaskInfoService taskInfoService;

    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    BasePageResp<TaskInfo> page(TaskInfoQuery query) {
        return taskInfoService.getTaskInfoPage(query);
    }


    @Operation(summary = "查询详情", description = "查询详情")
    @GetMapping("/{ids}")
    @Parameter(
            name = "ids",
            description = "ids",
            example = "1,2,3,4",
            in = ParameterIn.PATH
    )
    public List<TaskInfo> getInviteRewardsRuleByIds(@PathVariable("ids") List<Long> ids) {
        return taskInfoService.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 TaskInfoReq req, @PathVariable("id") Long id) {
        this.taskInfoService.updatetaskInfo(id, req);
    }

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


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