#ifndef _DB_MYSQL_SQL_SCRIPT_SYNC_WRAPPER_H_
#define _DB_MYSQL_SQL_SCRIPT_SYNC_WRAPPER_H_

#include "db_mysql_sql_script_sync.h"
#include "GrtTemplates.h"
#include "db_mysql_validation_page_wrapper.h"

namespace MySQL {
namespace GUI {
namespace Workbench {
namespace Plugins {
namespace DbMySQLScriptSync {

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Collections::Generic;
using namespace MySQL::Grt;

public ref class DbMySQLScriptSync : public MySQL::GUI::Workbench::Plugins::DbMySQL::DbMySQLValidationPage
{
  //::DbMySQLScriptSync *_inner;

public:
  DbMySQLScriptSync(MySQL::Grt::GrtManager ^grt_manager) 
    : DbMySQLValidationPage(new ::DbMySQLScriptSync(grt_manager->get_unmanaged_object()))
  {}

  ::DbMySQLScriptSync *get_unmanaged_object()
  { return static_cast<::DbMySQLScriptSync *>(_inner); }

  //MySQL::Grt::GrtManager^ get_grt_manager() 
  //{ return gcnew MySQL::Grt::GrtManager(_inner->get_grt_manager()); }
  
  void set_option(String^ name, String^ value)
  { get_unmanaged_object()->set_option(NativeToCppString(name), NativeToCppString(value)); }

  void start_sync()
  { get_unmanaged_object()->start_sync(); }

  ::MySQL::Grt::TreeModel^ init_diff_tree(
    List<String ^> ^schemata, MySQL::Grt::GrtValue^ cat1, MySQL::Grt::GrtValue^ cat2)
  { 
    try {
      if(schemata != nullptr)
      {
        ValueRef cat1_value(cat1->get_unmanaged_object());
        ValueRef cat2_value(cat2->get_unmanaged_object());

        std::vector<std::string> s= NativeToCppStringVector(schemata);
        return gcnew ::MySQL::Grt::TreeModel(get_unmanaged_object()->init_diff_tree(
          s, cat1_value, cat2_value)); 
      }
      else
      {
        return gcnew ::MySQL::Grt::TreeModel(get_unmanaged_object()->init_diff_tree(
          cat1->get_unmanaged_object(), 
          cat2->get_unmanaged_object())); 
      }
    } catch(std::logic_error *err) {
      throw gcnew System::ApplicationException(CppStringToNative(err->what()));
    }
  }

  void set_next_apply_direction(NodeId ^nodeid)
  { get_unmanaged_object()->set_next_apply_direction(*nodeid->get_unmanaged_object()); }

  String^ generate_diff_tree_script()
  { return CppStringToNative(get_unmanaged_object()->generate_diff_tree_script()); }

  String^ generate_diff_tree_report()
  { return CppStringToNative(get_unmanaged_object()->generate_diff_tree_report()); }


  String^ save_script_to_file(String^ script, String^ filename)
  { return CppStringToNative(get_unmanaged_object()->save_script_to_file(NativeToCppString(script), NativeToCppString(filename))); }

  void apply_changes_to_model()
  { get_unmanaged_object()->apply_changes_to_model(); }

  void update_model_old_names()
  { get_unmanaged_object()->update_model_old_names(); }
};

} // namespaces
}
}
}
}

#endif // _DB_MYSQL_SQL_SCRIPT_SYNC_WRAPPER_H_