#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   // 1. Initialize the account balance
   uc.DefineVariable("balance = 0.0");

   // 2. Define the DSL rules on the expression transformer
   auto t = uc.ExpressionTransformer();
   t.FromTo("DEPOSIT {@Number:amount}", "balance = balance + {amount}");
   t.FromTo("WITHDRAW {@Number:amount}", "balance = balance - {amount}");
   t.FromTo("INTEREST {@Number:rate}", "balance = balance * (1 + {rate} / 100.0)");

   // 3. Define the multi-line transaction script
   auto script = R"(
DEPOSIT 1000.00
WITHDRAW 50.75
INTEREST 0.5
WITHDRAW 200.00
)";

   cout << "Initial Balance: " << uc.Eval("balance") << endl;
   cout << "Processing script..." << endl;

   // 4. Evaluate the entire script.
   // Note: EvalStr returns the result of the LAST line.
   // The intermediate lines modify the 'balance' variable.
   uc.EvalStr(script);

   // 5. Get the final balance
   cout << "Final Balance: " << uc.EvalStr("balance") << endl;
}