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

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   {
      uCalc::Transformer validator;
      validator.Owned(); // Causes validator to be released when it goes out of scope

      // Rule 1: Must contain exactly one 'Host' setting.
      auto hostRule = validator.Pattern("Host: {@Alpha}").SetMinimum(1).SetMaximum(1);

      // Rule 2: Must contain at least one 'Port' setting.
      auto portRule = validator.Pattern("Port: {@Number}").SetMinimum(1);

      auto configFile_OK = R"(
Host: server1
Port: 80
Port: 443
)";
      auto configFile_FAIL = "Port: 80"; // Missing Host

      cout << "--- Testing Valid Config ---" << endl;
      validator.SetText(configFile_OK).Find();
      if (hostRule.Matches().Count() > 0 && portRule.Matches().Count() > 0) {
         cout << "Config file is valid." << endl;
      } else {
         cout << "Config file is invalid." << endl;
      }
      cout << endl;
      cout << "--- Testing Invalid Config ---" << endl;
      validator.SetText(configFile_FAIL).Find();
      // The Minimum(1) on hostRule causes it to have 0 matches if none are found.
      if (hostRule.Matches().Count() > 0 && portRule.Matches().Count() > 0) {
         cout << "Config file is valid." << endl;
      } else {
         cout << "Config file is invalid." << endl;
         if (hostRule.Matches().Count() == 0) {
            cout << "- Reason: Host rule failed (found " << hostRule.Matches().Count() << ", expected 1)." << endl;
         }
      }
   }
}