package {{packageName}}.core.runtime;

import net.ibizsys.central.dataentity.IDataEntityRuntime;
import net.ibizsys.central.dataentity.service.IDEService;
import net.ibizsys.central.r8.R8SystemRuntime;
import net.ibizsys.model.IPSDynaInstService;
import net.ibizsys.model.res.IPSSysUtil;
import net.ibizsys.runtime.res.ISysUtilRuntime;

public class SystemRuntimeBase extends R8SystemRuntime implements ISystemRuntime {

    @Override
    public String getName() {
        return "{{system.name}}";
    }

{{#if system.allPSSysUtils}}
    @Override
    protected ISysUtilRuntime createDefaultSysUtilRuntime(IPSSysUtil iPSSysUtil) {
{{#each system.allPSSysUtils as |sysUtil|}}
        {{#if (and (eq sysUtil.utilType "USER")) (unless sysUtil.pSSysSFPlugin)}}
        if(iPSSysUtil.getCodeName().equals("{{sysUtil.codeName}}"))
            return new {{packageName}}.core.runtime.sysutil.{{sysUtil.codeName}}();
        {{/if}}
{{/each}}
        return super.createDefaultSysUtilRuntime(iPSSysUtil);
    }

{{/if}}
    @Override
    protected void onInit() throws Exception {
        this.registerDEServiceObjs();
        super.onInit();
    }

    @Override
    public IDEService getDEService(IDataEntityRuntime iDataEntityRuntime) {
        if (!this.getSystemGatewayContext().isMultiSystemMode()) {
            return this.getSystemGatewayContext().getDEService("{{packageName}}.core.runtime.ISystemRuntime", iDataEntityRuntime.getId());
        }
        return super.getDEService(iDataEntityRuntime);
    }

    protected void registerDEServiceObjs() {
{{#each system.allPSDataEntities as |entity|}}
        this.registerDEServiceObj("{{entity.dynaModelFilePath}}","{entityService}");
{{/each}}
    }

}
