package cn.axzo.workflow.client.feign.manage;

import cn.axzo.workflow.client.annotation.WorkflowEngineFeignClient;
import cn.axzo.workflow.common.annotation.InvokeMode;
import cn.axzo.workflow.common.annotation.Manageable;
import cn.axzo.workflow.common.model.dto.print.PrintFieldDTO;
import cn.axzo.workflow.common.model.request.bpmn.print.PrintFieldQueryDTO;
import cn.axzo.workflow.common.model.request.bpmn.print.PrintTemplateConfigUpsertDTO;
import cn.azxo.framework.common.model.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

import static cn.axzo.workflow.common.enums.RpcInvokeModeEnum.SYNC;

/**
 * 打印相关的 API
 *
 * @author wangli
 * @since 2025-01-16 17:35
 */
@WorkflowEngineFeignClient
public interface PrintAdminApi {
    /**
     * 查询指定审批流程是否能打印，打印开关是否开启，是否存在打印模板
     *
     * @param processInstanceId
     * @return
     */
    @Operation(summary = "查询指定审批流程是否能打印，打印开关是否开启，是否存在打印模板")
    @GetMapping("/api/print/admin/template/exists")
    @InvokeMode(SYNC)
    CommonResponse<Boolean> hasPrintTemplate(@NotBlank(message = "流程实例不能为空") @RequestParam String processInstanceId);

    /**
     * 打印模板配置内容更新保存
     *
     * @param dto
     * @return
     */
    @Operation(summary = "打印模板配置内容更新保存")
    @PostMapping("/api/print/admin/template/upsert")
    @InvokeMode(SYNC)
    CommonResponse<Void> printTemplateConfig(@Validated @RequestBody PrintTemplateConfigUpsertDTO dto);

    /**
     * 获取打印模板中可打印的字段
     *
     * @param dto
     * @return
     */
    @Operation(summary = "获取打印模板中可打印的字段")
    @PostMapping("/api/print/admin/fields")
    @Manageable
    @InvokeMode(SYNC)
    CommonResponse<List<PrintFieldDTO>> getPrintFields(@Validated @RequestBody PrintFieldQueryDTO dto);

    /**
     * 获取指定流程下用于替换打印的相关变量
     *
     * @param processInstanceId
     * @return
     */
    @Operation(summary = "获取指定流程下用于替换打印的相关变量")
    @GetMapping("/api/print/admin/field/variables")
    @Manageable
    @InvokeMode(SYNC)
    CommonResponse<Map<String, Object>> getPrintFieldVariables(@NotBlank(message = "流程实例不能为空") @RequestParam String processInstanceId);
}
