package top.continew.admin.controller.business;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.continew.admin.business.model.query.TaskRecordHistoryQuery;
import top.continew.admin.business.model.req.TaskRecordHistoryAddReq;
import top.continew.admin.business.model.req.TaskRecordHistoryEditReq;
import top.continew.admin.business.model.resp.TaskRecordHistoryResp;
import top.continew.admin.business.service.TaskRecordHistoryService;
import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.web.model.R;

import java.util.List;

/**
 * 音视图文生成记录管理 API
 *
 * @author jiay
 * @since 2025/05/23 07:51
 */
@Tag(name = "音视图文生成记录管理 API")
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/taskRecordHistory")
public class TaskRecordHistoryController {

    private final TaskRecordHistoryService taskRecordHistoryService;

    @Operation(summary = "添加音视图文生成记录", description = "添加音视图文生成记录")
    @PostMapping("/add")
    public R<String> add(@RequestBody @Valid TaskRecordHistoryAddReq req) {
        return R.ok(taskRecordHistoryService.addTaskRecordHistory(req));
    }

    @Operation(summary = "编辑音视图文生成记录", description = "编辑音视图文生成记录")
    @PostMapping("/edit")
    public R<Void> edit(@RequestBody @Valid TaskRecordHistoryEditReq req) {
        return taskRecordHistoryService.editTaskRecordHistory(req) ? R.ok() : R.fail();
    }

    @Operation(summary = "删除音视图文生成记录", description = "删除音视图文生成记录")
    @DeleteMapping("/delete")
    public R<Void> delete(@RequestParam Long id) {
        return taskRecordHistoryService.deleteTaskRecordHistory(id) ? R.ok() : R.fail();
    }

    @Operation(summary = "获取音视图文生成记录", description = "获取音视图文生成记录")
    @GetMapping("/get")
    public R<TaskRecordHistoryResp> getTaskRecordHistory(@RequestParam(name = "id", required = true) Long id) {
        return R.ok(taskRecordHistoryService.getTaskRecordHistory(id));
    }

    @Operation(summary = "查询音视图文生成记录列表", description = "查询音视图文生成记录列表")
    @GetMapping("/list")
    public R<List<TaskRecordHistoryResp>> getTaskRecordHistoryList(TaskRecordHistoryQuery query) {
        return R.ok(taskRecordHistoryService.getTaskRecordHistoryList(query));
    }

    @Operation(summary = "分页查询音视图文生成记录列表", description = "分页查询音视图文生成记录列表")
    @GetMapping
    public R<PageResp<TaskRecordHistoryResp>> page(TaskRecordHistoryQuery query, @Validated PageQuery pageQuery) {
        return R.ok(taskRecordHistoryService.getTaskRecordHistoryPage(query, pageQuery));
    }

}