package com.seeyon.apps.esign.service;

import com.seeyon.ctp.common.AppContext;

import java.util.List;
import java.util.Map;

public class ContractCreateService {

    private EsignByTemplateService templateService = (EsignByTemplateService) AppContext.getBean("esignByTemplateService");
    private List<SignParamBuildFactory> signParamBuildFactories;

    public String startSign(SignParamSource source) throws Exception {
        for (SignParamBuildFactory factory : signParamBuildFactories) {
            if(factory.support(source)){
                Map<String, Object> buildParam = factory.buildParam(source);
                if (buildParam == null) throw new RuntimeException("签署参数构建失败");
                return templateService.createBySignTemplate(source.getAppId(),buildParam);
            }
        }
        return null;
    }

    public List<SignParamBuildFactory> getSignParamBuildFactories() {
        return signParamBuildFactories;
    }

    public void setSignParamBuildFactories(List<SignParamBuildFactory> signParamBuildFactories) {
        this.signParamBuildFactories = signParamBuildFactories;
    }
}
