#include "stdafx.h"

//#pragma warning(disable: 4793)  // 'vararg' causes native code generation

#include "MySQLTableEditorBE.h"
#include "grtdb/db_object_helpers.h"

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

//MySQLTableColumnsListBE::MySQLTableColumnsListBE(MySQLTableEditorBE^ owner)
//  : TableColumnsListBE(owner->get_unmanaged_object())
//{}

MySQLTableColumnsListBE::MySQLTableColumnsListBE(::MySQLTableColumnsListBE *inn)
  : TableColumnsListBE(inn)
{}

#pragma unmanaged

// TODO: this function is duplicated in ViewEditorBE.cpp wrapper, avoid duplication

//static inline db_mgmt_RdbmsRef get_rdbms_for_db_object(const ::grt::ValueRef &object)
//{
//  GrtObjectRef parent= GrtObjectRef::cast_from(object);
//  while (parent.is_valid() && !parent.is_instance("db.Catalog"))
//    parent= parent->owner();
//  return workbench_physical_ModelRef::cast_from(parent->owner())->rdbms();
//}

#pragma managed

MySQLTableEditorBE::MySQLTableEditorBE(MySQL::Grt::GrtManager^ grtm, MySQL::Grt::GrtValue^ arglist)
: TableEditorBE(
      new ::MySQLTableEditorBE(grtm->get_unmanaged_object(), 
      db_mysql_TableRef::cast_from(::grt::BaseListRef::cast_from(arglist->get_unmanaged_object()).get(0)),
      get_rdbms_for_db_object(::grt::BaseListRef::cast_from(arglist->get_unmanaged_object()).get(0))
      )
    )
{
}

MySQLTableColumnsListBE^ MySQLTableEditorBE::get_columns() 
{ return gcnew MySQLTableColumnsListBE(get_unmanaged_object()->get_columns()); }


MySQLTablePartitionTreeBE^ MySQLTableEditorBE::get_partitions()
{
  return gcnew MySQLTablePartitionTreeBE(get_unmanaged_object()->get_partitions());
}


};  // namespace Plugins
};  // namespace Workbench
};  // namespace GUI
};  // namespace MySQL
