package cn.axzo.workflow.form.engine.api;

import cn.axzo.workflow.form.engine.cmd.CustomCreateFormInstanceCmd;
import cn.axzo.workflow.form.engine.cmd.CustomGetVariablesFromFormSubmissionCmd;
import org.flowable.form.api.FormInfo;
import org.flowable.form.api.FormInstance;
import org.flowable.form.engine.FormEngineConfiguration;
import org.flowable.form.engine.impl.FormServiceImpl;

import java.util.Map;

/**
 * 自定义扩展表单引擎中的 FormService
 *
 * @author wangli
 * @since 2025-01-22 11:19
 */
public class CustomFormServiceImpl extends FormServiceImpl {
    public CustomFormServiceImpl(FormEngineConfiguration engineConfiguration) {
        super(engineConfiguration);
    }

    @Override
    public void validateFormFields(FormInfo formInfo, Map<String, Object> values) {
        // StartEvent Form Fields Validation
        super.validateFormFields(formInfo, values);
    }

    @Override
    public FormInstance createFormInstance(Map<String, Object> variables, FormInfo formInfo, String taskId, String processInstanceId, String processDefinitionId, String tenantId, String outcome) {
        return commandExecutor.execute(new CustomCreateFormInstanceCmd(formInfo, variables, taskId, processInstanceId, processDefinitionId, tenantId, outcome));
    }

    @Override
    public Map<String, Object> getVariablesFromFormSubmission(FormInfo formInfo, Map<String, Object> values) {
        return commandExecutor.execute(new CustomGetVariablesFromFormSubmissionCmd(formInfo, values));
    }

    @Override
    public Map<String, Object> getVariablesFromFormSubmission(FormInfo formInfo, Map<String, Object> values, String outcome) {
        return commandExecutor.execute(new CustomGetVariablesFromFormSubmissionCmd(formInfo, values, outcome));
    }
}
