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

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto FruitsXML =
   R"(
<Fruits>
  <Fruit CommonName='Apple' />
  <Fruit CommonName='Banana' />
  <Fruit CommonName='Orange' />
  <Fruit CommonName='Grapes' />
</Fruits>
)";

   uCalc::Transformer t;
   auto fruitsTagRule = t.FromTo("<Fruits>", "List of fruits");
   auto fruitRule = t.FromTo("CommonName={@string:name}", "- {name}");

   cout << "--- Using Maximum (Rule-Level Invalidation) ---" << endl;
   // The fruitRule will fail because there are 4 fruits, exceeding the max of 3.
   fruitRule.Maximum(3);
   t.Filter(FruitsXML);
   cout << "Match count: " << t.Matches().Count() << endl; // The 'fruitsTagRule' still matches and is counted.
   cout << t.Matches().Text() << endl;

   cout << "" << endl;
   cout << "--- Using GlobalMaximum (Transformer-Level Invalidation) ---" << endl;
   fruitRule.Maximum(-1); // Reset local maximum to default (unlimited).
   fruitRule.GlobalMaximum(3); // The entire transformer will fail if more than 3 fruits are found.
   t.Filter(FruitsXML);
   cout << "Match count: " << t.Matches().Count() << endl; // All matches (including fruitsTagRule) are invalidated.
   cout << t.Matches().Text() << endl;
}