// Copyright (c) Microsoft Corporation
// All rights reserved. 
//
// Licensed under the Apache License, Version 2.0 (the ""License""); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED ON AN  *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 
//
// See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.

// TODO: Verify that this is is still needed..
#define NTDDI_VERSION 0x06010000

#include <v8.h>
#include "nan.h"
#include <string>
#include <ppltasks.h>
#include "CollectionsConverter.h"
#include "CollectionsWrap.h"
#include "node-async.h"
#include "NodeRtUtils.h"
#include "OpaqueWrapper.h"
#include "WrapperBase.h"

#using <Windows.WinMD>

// this undefs fixes the issues of compiling Windows.Data.Json, Windows.Storag.FileProperties, and Windows.Stroage.Search
// Some of the node header files brings windows definitions with the same names as some of the WinRT methods
#undef DocumentProperties
#undef GetObject
#undef CreateEvent
#undef FindText
#undef SendMessage

const char* REGISTRATION_TOKEN_MAP_PROPERTY_NAME = "__registrationTokenMap__";

using v8::Array;
using v8::String;
using v8::Handle;
using v8::Value;
using v8::Boolean;
using v8::Integer;
using v8::FunctionTemplate;
using v8::Object;
using v8::Local;
using v8::Function;
using v8::Date;
using v8::Number;
using v8::PropertyAttribute;
using v8::Primitive;
using Nan::HandleScope;
using Nan::Persistent;
using Nan::Undefined;
using Nan::True;
using Nan::False;
using Nan::Null;
using Nan::MaybeLocal;
using Nan::EscapableHandleScope;
using Nan::HandleScope;
using Nan::TryCatch;
using namespace concurrency;

namespace NodeRT { namespace Windows { namespace ApplicationModel { namespace DataTransfer { namespace DragDrop { 



  static void InitDragDropModifiersEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("DragDropModifiers").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::None)));
	Nan::Set(enumObject, Nan::New<String>("shift").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::Shift)));
	Nan::Set(enumObject, Nan::New<String>("control").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::Control)));
	Nan::Set(enumObject, Nan::New<String>("alt").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::Alt)));
	Nan::Set(enumObject, Nan::New<String>("leftButton").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::LeftButton)));
	Nan::Set(enumObject, Nan::New<String>("middleButton").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::MiddleButton)));
	Nan::Set(enumObject, Nan::New<String>("rightButton").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::DataTransfer::DragDrop::DragDropModifiers::RightButton)));
  }



  
} } } } } 

NAN_MODULE_INIT(init)
{
  // we ignore failures for now since it probably means that the initialization already happened for STA, and that's cool
  CoInitializeEx(nullptr, COINIT_MULTITHREADED);
  //if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)))
  /*{
    Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"error in CoInitializeEx()")));
    return;
  }*/
  
  NodeRT::Windows::ApplicationModel::DataTransfer::DragDrop::InitDragDropModifiersEnum(target);

  NodeRT::Utils::RegisterNameSpace("Windows.ApplicationModel.DataTransfer.DragDrop", target);
}


NODE_MODULE(binding, init)