/*      _                   _ _
  _____| |__ ___ _ __  _ __(_| |___ _ _
 (_-/ _` / _/ _ | '  \| '_ | | / -_| '_|
 /__\__,_\__\___|_|_|_| .__|_|_\___|_|
                      |_|
 Copyright (c) 2013-2018 transentis management & consulting. All rights reserved.
*/
module.exports = () => {

{{{header}}}

// Simulation Buildins
let dt = {{specs.dt}}
let starttime = {{specs.start}}
let stoptime = {{specs.stop}}
let m, p, d

return {
	equations: m = {
		/* stocks */{{#each stocks}}
		'{{{name}}}': t => {{{expression}}},
	{{/each}}	/* flows */{{#each flows}}
		'{{{name}}}': t => {{{expression}}},
	{{/each}}

		/* converters */{{#each converters}}
		'{{{name}}}': t => {{{expression}}},
	{{/each}}	/* gf */{{#each gf}}
		'{{{name}}}': t =>
			LERP({{{expression}}},p['{{{name}}}']),
	{{/each}}

		/* constants */{{#each constants}}
		'{{{name}}}': t => {{{expression}}},
	{{/each}}
	},
	points: p = {
	{{#each gf}}	'{{{name}}}': [ {{#each points}}{{#if @index}},{{/if}}[{{{this}}}]{{/each}} ],
	{{/each}} },
	dimensions: d = {
	{{#each dimensions}}	'{{{name}}}': {
			labels: [ {{#each labels}}{{#if @index}},{{/if}}'{{{this}}}'{{/each}} ],
			variables: [ {{#each variables}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}} ]
		},
	{{/each}} },
	stocks: [{{#each stocks}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}}],
	flows: [{{#each flows}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}}],
	converters: [{{#each converters}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}}],
	gf: [{{#each gf}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}}],
	constants: [{{#each constants}}{{#if @index}},{{/if}}'{{{name}}}'{{/each}}],
	events: [{{#each events}}{{#if @index}},{{/if}}
		{ key:'{{entity}}',threshold:{{threshold}},direction:'{{{direction}}}',repeat:'{{repeat}}',interval:{{interval}},messages:[{{#each messages}}{{#if @index}},{{/if}}{ message:'{{message}}',action:'{{action}}'}{{/each}}]}{{/each}}
	],
	specs: () => ({
		starttime: starttime,
		stoptime: stoptime,
		dt: dt,
		time_units: '{{specs.units}}',
		method: '{{specs.method}}'
	}),
	setDT: v => { dt = v },
	setStarttime: v => { starttime = v },
	setStoptime: v => { stoptime = v }
}

}
