% ------------------------------------------------------------------------------------------------------
% Demonstrates the ECA runtime with different variants of ECA rule types

% Uses the \ContractLog\ecaruntime.prova implementation of the ContractLog framework
% ------------------------------------------------------------------------------------------------------

:-eval(consult('ContractLog/math.prova')).
:-eval(consult('ContractLog/list.prova')).
:-eval(consult('ContractLog/list_math.prova')).
:-eval(consult('ContractLog/datetime.prova')).
:-eval(consult('ContractLog/timeinterval.prova')).
:-eval(consult('ContractLog/ecaruntime.prova')).

%-----------------------------------------------------------------------
% Define ECA rules
%-----------------------------------------------------------------------




% +++++++++++++++  Full ECA rule with all parts ++++++++++++++
% 
%ECA 1: Full ECA rule rings alarm every 10 seconds

eca(every10Sec(),event(),condition(),startAlarm(),post(),else()). % ECA rule definition

%TIME
every10Sec() :-
	sysTime(DT),
	interval(timespan(0,0,0,10), DT).

%EVENT
event().

%CONDITION
condition().

%ACTION
startAlarm() :-	
	println(["Fire TECAPEl rule 1: Alert !!!!!!!!! Alert !!!!!!!!"]).

%POSTCONDITIOn
post().	
	
%ELSE ACTION
else().



% +++++++++++++++   (T)ECA rule ++++++++++++++
% 
%ECA 2:  (T)ECA rule rings alarm every 5 seconds

eca(every5Sec(),event(),condition(),startAlarm2()). % ECA rule definition

%TIME
every5Sec() :-
	sysTime(DT),
	interval(timespan(0,0,0,5), DT).
	
%ACTION
startAlarm2() :-	
	println(["Fire TECA rule 2: Alert !!!!!!!!! Alert !!!!!!!!"]).
	
	
	
	
% +++++++++++++++   ECA rule ++++++++++++++
% 
%ECA 3: Traditional ECA rule rings alarm whenever event happens

eca(event(),condition(),startAlarm3()). % ECA rule definition

%ACTION
startAlarm3() :-	
	println(["Fire ECA rule 3: Alert !!!!!!!!! Alert !!!!!!!!"]).
	
	
	
% +++++++++++++++   CA rule ++++++++++++++
% 
%CA 4: CA (production rule) rule rings alarm when condition holds

eca(condition(),startAlarm4()). % ECA rule definition

%ACTION
startAlarm4() :-	
	println(["Fire production rules 4: Alert !!!!!!!!! Alert !!!!!!!!"]).
	
	
	
%-----------------------------------------------------------------------
% Start the ECA runtime
%-----------------------------------------------------------------------

start():-
	startECARuntime(".\examples\function_tests\eca_runtime\alarmclock.prova").
	
:- solve(start()).
	