// Copyright (c) The NodeRT Contributors
// 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::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 Phone { namespace Speech { namespace Recognition { 



  static void InitSpeechRecognitionUIStatusEnum(const Local<Object> exports) {
    HandleScope scope;

    Local<Object> enumObject = Nan::New<Object>();

    Nan::Set(exports, Nan::New<String>("SpeechRecognitionUIStatus").ToLocalChecked(), enumObject);
    Nan::Set(enumObject, Nan::New<String>("succeeded").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Phone::Speech::Recognition::SpeechRecognitionUIStatus::Succeeded)));
    Nan::Set(enumObject, Nan::New<String>("busy").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Phone::Speech::Recognition::SpeechRecognitionUIStatus::Busy)));
    Nan::Set(enumObject, Nan::New<String>("cancelled").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Phone::Speech::Recognition::SpeechRecognitionUIStatus::Cancelled)));
    Nan::Set(enumObject, Nan::New<String>("preempted").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Phone::Speech::Recognition::SpeechRecognitionUIStatus::Preempted)));
    Nan::Set(enumObject, Nan::New<String>("privacyPolicyDeclined").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::Phone::Speech::Recognition::SpeechRecognitionUIStatus::PrivacyPolicyDeclined)));
  }




} } } } } 

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::Phone::Speech::Recognition::InitSpeechRecognitionUIStatusEnum(target);


  NodeRT::Utils::RegisterNameSpace("Windows.Phone.Speech.Recognition", target);
}



NODE_MODULE(binding, init)
