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.web.bind.annotation.*;

/**
 * 表单数据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;

    @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) {
        // 暂不支持导出
    }
}

