#include <VmbCPP/VmbCPP.h>
#include <string>
#include <vector>
#include <fmt/core.h>

//Forward declaration of a function that uses part of 3rd party lib AftrBurner
void bar( std::vector<std::string> const& args );

 // Just calls Vimba Startup()
void foo()
{
   using namespace VmbCPP;
   VmbCPP::VmbSystem& s = VmbSystem::GetInstance();  // Get a reference to the VimbaSystem singleton

   fmt::print("Calling Vimba Startup() from foo()...\n");
   //VmbErrorType err = s.Startup("/repos/VimbaX_2023-1/cti/VimbaCSITL.cti"); // Initialize the Vmb API
   VmbErrorType err = s.Startup(); // Initialize the Vmb API
   fmt::print( "Startup() result is {:s}\n", std::to_string(err) );
   fmt::print("RETURNED from calling startup()\n");
   if (VmbErrorSuccess == err)
      fmt::print("Startup successful\n\n");
   else if (VmbErrorAlready == err)
      fmt::print("Already init...\n");
   else
   	fmt::print( "vimba init failed...{:d}\n", (int)err);
   VmbVersionInfo_t versionInfo;
   s.QueryVersion(versionInfo);
   fmt::print("Vmb Version Major: {} Minor: {} Patch: {}\n\n",
              versionInfo.major, versionInfo.minor, versionInfo.patch);
}


int main(int argc, char *argv[])
{
  fmt::print( "In main\n" );
  //std::this_thread::sleep_for( std::chrono::seconds(2) );
  std::vector<std::string> args{argv, argv + argc};
  //foo(); //doesn't matter where foo() is called, always crashes when linking 3rd party lib
  fmt::print( "Using 3rd party lib...\n" );
  bar( args ); //When NOT linking AftrBurner, we cannot call into the library, so we ignore this call and Vimba Startup() works
  fmt::print( "Finished using 3rd party lib...\n" );

  foo(); 
  VmbCPP::VmbSystem::GetInstance().Shutdown();
  fmt::print( "Exited AftrBurner Engine Normally...\n" );
  return 0;
}
