package com.qqchen.deploy.backend.workflow.api;

import com.qqchen.deploy.backend.framework.api.Response;
import com.qqchen.deploy.backend.framework.controller.BaseController;
import com.qqchen.deploy.backend.workflow.dto.FormDataDTO;
import com.qqchen.deploy.backend.workflow.dto.query.FormDataQuery;
import com.qqchen.deploy.backend.workflow.entity.FormData;
import com.qqchen.deploy.backend.workflow.service.IFormDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * 表单数据API控制器
 *
 * @author qqchen
 * @date 2025-10-24
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/forms/data")
@Tag(name = "表单数据管理", description = "表单数据管理相关接口")
public class FormDataApiController extends BaseController<FormData, FormDataDTO, Long, FormDataQuery> {

    @Resource
    private IFormDataService formDataService;

    @Override
    public Response<FormDataDTO> create(FormDataDTO dto) {
        return super.create(dto);
    }

    @Override
    public Response<FormDataDTO> update(Long aLong, FormDataDTO dto) {
        return super.update(aLong, dto);
    }

    @Override
    public Response<Void> delete(Long aLong) {
        return super.delete(aLong);
    }

    @Override
    public Response<FormDataDTO> findById(Long aLong) {
        return super.findById(aLong);
    }

    @Override
    public Response<List<FormDataDTO>> findAll() {
        return super.findAll();
    }

    @Override
    public Response<Page<FormDataDTO>> page(FormDataQuery query) {
        return super.page(query);
    }

    @Override
    public Response<List<FormDataDTO>> findAll(FormDataQuery query) {
        return super.findAll(query);
    }

    @Override
    public CompletableFuture<Response<Void>> batchProcess(List<FormDataDTO> dtos) {
        return super.batchProcess(dtos);
    }

    @Operation(summary = "提交表单数据")
    @PostMapping("/submit")
    public Response<FormDataDTO> submit(@RequestBody FormDataDTO dto) {
        FormDataDTO result = formDataService.submit(dto);
        return Response.success(result);
    }

    @Operation(summary = "根据业务标识查询表单数据")
    @GetMapping("/business/{businessKey}")
    public Response<FormDataDTO> getByBusinessKey(
        @Parameter(description = "业务标识", required = true) @PathVariable String businessKey
    ) {
        FormDataDTO result = formDataService.getByBusinessKey(businessKey);
        return Response.success(result);
    }

    @Override
    protected void exportData(jakarta.servlet.http.HttpServletResponse response, java.util.List<FormDataDTO> data) {
        // 暂不支持导出
    }
}

