// 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 Calls { namespace Background { 

  v8::Local<v8::Value> WrapPhoneCallBlockedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ wintRtInstance);
  ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ UnwrapPhoneCallBlockedTriggerDetails(Local<Value> value);
  
  v8::Local<v8::Value> WrapPhoneCallOriginDataRequestTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ wintRtInstance);
  ::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ UnwrapPhoneCallOriginDataRequestTriggerDetails(Local<Value> value);
  
  v8::Local<v8::Value> WrapPhoneNewVoicemailMessageTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ wintRtInstance);
  ::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ UnwrapPhoneNewVoicemailMessageTriggerDetails(Local<Value> value);
  
  v8::Local<v8::Value> WrapPhoneLineChangedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ wintRtInstance);
  ::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ UnwrapPhoneLineChangedTriggerDetails(Local<Value> value);
  


  static void InitPhoneCallBlockedReasonEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("PhoneCallBlockedReason").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("inCallBlockingList").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedReason::InCallBlockingList)));
	Nan::Set(enumObject, Nan::New<String>("privateNumber").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedReason::PrivateNumber)));
	Nan::Set(enumObject, Nan::New<String>("unknownNumber").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedReason::UnknownNumber)));
  }


  static void InitPhoneTriggerTypeEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("PhoneTriggerType").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("newVoicemailMessage").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::NewVoicemailMessage)));
	Nan::Set(enumObject, Nan::New<String>("callHistoryChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::CallHistoryChanged)));
	Nan::Set(enumObject, Nan::New<String>("lineChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::LineChanged)));
	Nan::Set(enumObject, Nan::New<String>("airplaneModeDisabledForEmergencyCall").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::AirplaneModeDisabledForEmergencyCall)));
	Nan::Set(enumObject, Nan::New<String>("callOriginDataRequest").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::CallOriginDataRequest)));
	Nan::Set(enumObject, Nan::New<String>("callBlocked").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneTriggerType::CallBlocked)));
  }


  static void InitPhoneLineChangeKindEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("PhoneLineChangeKind").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("added").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineChangeKind::Added)));
	Nan::Set(enumObject, Nan::New<String>("removed").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineChangeKind::Removed)));
	Nan::Set(enumObject, Nan::New<String>("propertiesChanged").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineChangeKind::PropertiesChanged)));
  }


  static void InitPhoneLinePropertiesEnum(const Local<Object> exports)
  {
    HandleScope scope;
    
	Local<Object> enumObject = Nan::New<Object>();
    Nan::Set(exports, Nan::New<String>("PhoneLineProperties").ToLocalChecked(), enumObject);
	Nan::Set(enumObject, Nan::New<String>("none").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::None)));
	Nan::Set(enumObject, Nan::New<String>("brandingOptions").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::BrandingOptions)));
	Nan::Set(enumObject, Nan::New<String>("canDial").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::CanDial)));
	Nan::Set(enumObject, Nan::New<String>("cellularDetails").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::CellularDetails)));
	Nan::Set(enumObject, Nan::New<String>("displayColor").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::DisplayColor)));
	Nan::Set(enumObject, Nan::New<String>("displayName").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::DisplayName)));
	Nan::Set(enumObject, Nan::New<String>("networkName").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::NetworkName)));
	Nan::Set(enumObject, Nan::New<String>("networkState").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::NetworkState)));
	Nan::Set(enumObject, Nan::New<String>("transport").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::Transport)));
	Nan::Set(enumObject, Nan::New<String>("voicemail").ToLocalChecked(), Nan::New<Integer>(static_cast<int>(::Windows::ApplicationModel::Calls::Background::PhoneLineProperties::Voicemail)));
  }



  
  static bool IsCallsBackgroundContractJsObject(Local<Value> value)
  {
    if (!value->IsObject())
    {
      return false;
    }

    Local<String> symbol;
    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();

    return true;
  }

  ::Windows::ApplicationModel::Calls::Background::CallsBackgroundContract CallsBackgroundContractFromJsObject(Local<Value> value)
  {
    HandleScope scope;
    ::Windows::ApplicationModel::Calls::Background::CallsBackgroundContract returnValue;
    
    if (!value->IsObject())
    {
      Nan::ThrowError(Nan::TypeError(NodeRT::Utils::NewString(L"Unexpected type, expected an object")));
      return returnValue;
    }

    Local<Object> obj = Nan::To<Object>(value).ToLocalChecked();
    Local<String> symbol;

    return returnValue;
  }

  Local<Value> CallsBackgroundContractToJsObject(::Windows::ApplicationModel::Calls::Background::CallsBackgroundContract value)
  {
    EscapableHandleScope scope;

    Local<Object> obj = Nan::New<Object>();

    
    return scope.Escape(obj);
  }

  
  class PhoneCallBlockedTriggerDetails : public WrapperBase
  {
  public:    
    static void Init(const Local<Object> exports)
    {
      HandleScope scope;
      
      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
      s_constructorTemplate.Reset(localRef);
      localRef->SetClassName(Nan::New<String>("PhoneCallBlockedTriggerDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("callBlockedReason").ToLocalChecked(), CallBlockedReasonGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("lineId").ToLocalChecked(), LineIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("phoneNumber").ToLocalChecked(), PhoneNumberGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("PhoneCallBlockedTriggerDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    PhoneCallBlockedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ instance)
    {
      _instance = instance;
    }
    
    
    static void New(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

	    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This()))
      {
        if (info.Length() > 0)
        {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++)
          {
            argsPtr[i] = info[i];
          }

		  MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
		  if (res.IsEmpty())
		  {
			  return;
		  }
		  info.GetReturnValue().Set(res.ToLocalChecked());
		  return;
		}
		else
		{
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);
          if (res.IsEmpty())
          {
            return;
          }
          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }
      
      ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      PhoneCallBlockedTriggerDetails *wrapperInstance = new PhoneCallBlockedTriggerDetails(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


	
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info)
    {
		HandleScope scope;
		if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^>(info[0]))
		{
			Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
			return;
		}

		::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapPhoneCallBlockedTriggerDetails(winRtInstance));
    }


  



    static void CallBlockedReasonGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneCallBlockedTriggerDetails *wrapper = PhoneCallBlockedTriggerDetails::Unwrap<PhoneCallBlockedTriggerDetails>(info.This());

      try 
      {
        ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedReason result = wrapper->_instance->CallBlockedReason;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void LineIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneCallBlockedTriggerDetails *wrapper = PhoneCallBlockedTriggerDetails::Unwrap<PhoneCallBlockedTriggerDetails>(info.This());

      try 
      {
        ::Platform::Guid result = wrapper->_instance->LineId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void PhoneNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneCallBlockedTriggerDetails *wrapper = PhoneCallBlockedTriggerDetails::Unwrap<PhoneCallBlockedTriggerDetails>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->PhoneNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapPhoneCallBlockedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ wintRtInstance);
    friend ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ UnwrapPhoneCallBlockedTriggerDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> PhoneCallBlockedTriggerDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapPhoneCallBlockedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ winRtInstance)
  {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr)
    {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(PhoneCallBlockedTriggerDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::ApplicationModel::Calls::Background::PhoneCallBlockedTriggerDetails^ UnwrapPhoneCallBlockedTriggerDetails(Local<Value> value)
  {
     return PhoneCallBlockedTriggerDetails::Unwrap<PhoneCallBlockedTriggerDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitPhoneCallBlockedTriggerDetails(Local<Object> exports)
  {
    PhoneCallBlockedTriggerDetails::Init(exports);
  }

  class PhoneCallOriginDataRequestTriggerDetails : public WrapperBase
  {
  public:    
    static void Init(const Local<Object> exports)
    {
      HandleScope scope;
      
      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
      s_constructorTemplate.Reset(localRef);
      localRef->SetClassName(Nan::New<String>("PhoneCallOriginDataRequestTriggerDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("phoneNumber").ToLocalChecked(), PhoneNumberGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("requestId").ToLocalChecked(), RequestIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("PhoneCallOriginDataRequestTriggerDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    PhoneCallOriginDataRequestTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ instance)
    {
      _instance = instance;
    }
    
    
    static void New(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

	    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This()))
      {
        if (info.Length() > 0)
        {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++)
          {
            argsPtr[i] = info[i];
          }

		  MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
		  if (res.IsEmpty())
		  {
			  return;
		  }
		  info.GetReturnValue().Set(res.ToLocalChecked());
		  return;
		}
		else
		{
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);
          if (res.IsEmpty())
          {
            return;
          }
          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }
      
      ::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      PhoneCallOriginDataRequestTriggerDetails *wrapperInstance = new PhoneCallOriginDataRequestTriggerDetails(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


	
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info)
    {
		HandleScope scope;
		if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^>(info[0]))
		{
			Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
			return;
		}

		::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapPhoneCallOriginDataRequestTriggerDetails(winRtInstance));
    }


  



    static void PhoneNumberGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneCallOriginDataRequestTriggerDetails *wrapper = PhoneCallOriginDataRequestTriggerDetails::Unwrap<PhoneCallOriginDataRequestTriggerDetails>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->PhoneNumber;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void RequestIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneCallOriginDataRequestTriggerDetails *wrapper = PhoneCallOriginDataRequestTriggerDetails::Unwrap<PhoneCallOriginDataRequestTriggerDetails>(info.This());

      try 
      {
        ::Platform::Guid result = wrapper->_instance->RequestId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapPhoneCallOriginDataRequestTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ wintRtInstance);
    friend ::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ UnwrapPhoneCallOriginDataRequestTriggerDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> PhoneCallOriginDataRequestTriggerDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapPhoneCallOriginDataRequestTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ winRtInstance)
  {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr)
    {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(PhoneCallOriginDataRequestTriggerDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::ApplicationModel::Calls::Background::PhoneCallOriginDataRequestTriggerDetails^ UnwrapPhoneCallOriginDataRequestTriggerDetails(Local<Value> value)
  {
     return PhoneCallOriginDataRequestTriggerDetails::Unwrap<PhoneCallOriginDataRequestTriggerDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitPhoneCallOriginDataRequestTriggerDetails(Local<Object> exports)
  {
    PhoneCallOriginDataRequestTriggerDetails::Init(exports);
  }

  class PhoneNewVoicemailMessageTriggerDetails : public WrapperBase
  {
  public:    
    static void Init(const Local<Object> exports)
    {
      HandleScope scope;
      
      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
      s_constructorTemplate.Reset(localRef);
      localRef->SetClassName(Nan::New<String>("PhoneNewVoicemailMessageTriggerDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
                              
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("lineId").ToLocalChecked(), LineIdGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("operatorMessage").ToLocalChecked(), OperatorMessageGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("voicemailCount").ToLocalChecked(), VoicemailCountGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("PhoneNewVoicemailMessageTriggerDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    PhoneNewVoicemailMessageTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ instance)
    {
      _instance = instance;
    }
    
    
    static void New(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

	    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This()))
      {
        if (info.Length() > 0)
        {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++)
          {
            argsPtr[i] = info[i];
          }

		  MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
		  if (res.IsEmpty())
		  {
			  return;
		  }
		  info.GetReturnValue().Set(res.ToLocalChecked());
		  return;
		}
		else
		{
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);
          if (res.IsEmpty())
          {
            return;
          }
          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }
      
      ::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      PhoneNewVoicemailMessageTriggerDetails *wrapperInstance = new PhoneNewVoicemailMessageTriggerDetails(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


	
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info)
    {
		HandleScope scope;
		if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^>(info[0]))
		{
			Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
			return;
		}

		::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapPhoneNewVoicemailMessageTriggerDetails(winRtInstance));
    }


  



    static void LineIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneNewVoicemailMessageTriggerDetails *wrapper = PhoneNewVoicemailMessageTriggerDetails::Unwrap<PhoneNewVoicemailMessageTriggerDetails>(info.This());

      try 
      {
        ::Platform::Guid result = wrapper->_instance->LineId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void OperatorMessageGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneNewVoicemailMessageTriggerDetails *wrapper = PhoneNewVoicemailMessageTriggerDetails::Unwrap<PhoneNewVoicemailMessageTriggerDetails>(info.This());

      try 
      {
        Platform::String^ result = wrapper->_instance->OperatorMessage;
        info.GetReturnValue().Set(NodeRT::Utils::NewString(result->Data()));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void VoicemailCountGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneNewVoicemailMessageTriggerDetails *wrapper = PhoneNewVoicemailMessageTriggerDetails::Unwrap<PhoneNewVoicemailMessageTriggerDetails>(info.This());

      try 
      {
        int result = wrapper->_instance->VoicemailCount;
        info.GetReturnValue().Set(Nan::New<Integer>(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapPhoneNewVoicemailMessageTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ wintRtInstance);
    friend ::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ UnwrapPhoneNewVoicemailMessageTriggerDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> PhoneNewVoicemailMessageTriggerDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapPhoneNewVoicemailMessageTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ winRtInstance)
  {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr)
    {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(PhoneNewVoicemailMessageTriggerDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::ApplicationModel::Calls::Background::PhoneNewVoicemailMessageTriggerDetails^ UnwrapPhoneNewVoicemailMessageTriggerDetails(Local<Value> value)
  {
     return PhoneNewVoicemailMessageTriggerDetails::Unwrap<PhoneNewVoicemailMessageTriggerDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitPhoneNewVoicemailMessageTriggerDetails(Local<Object> exports)
  {
    PhoneNewVoicemailMessageTriggerDetails::Init(exports);
  }

  class PhoneLineChangedTriggerDetails : public WrapperBase
  {
  public:    
    static void Init(const Local<Object> exports)
    {
      HandleScope scope;
      
      Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(New);
      s_constructorTemplate.Reset(localRef);
      localRef->SetClassName(Nan::New<String>("PhoneLineChangedTriggerDetails").ToLocalChecked());
      localRef->InstanceTemplate()->SetInternalFieldCount(1);
      
            
      Nan::SetPrototypeMethod(localRef, "hasLinePropertyChanged", HasLinePropertyChanged);
      
                        
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("changeType").ToLocalChecked(), ChangeTypeGetter);
      Nan::SetAccessor(localRef->PrototypeTemplate(), Nan::New<String>("lineId").ToLocalChecked(), LineIdGetter);
      
      Local<Object> constructor = Nan::To<Object>(Nan::GetFunction(localRef).ToLocalChecked()).ToLocalChecked();
	  Nan::SetMethod(constructor, "castFrom", CastFrom);


      Nan::Set(exports, Nan::New<String>("PhoneLineChangedTriggerDetails").ToLocalChecked(), constructor);
    }


    virtual ::Platform::Object^ GetObjectInstance() const override
    {
      return _instance;
    }

  private:
    
    PhoneLineChangedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ instance)
    {
      _instance = instance;
    }
    
    
    static void New(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

	    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(s_constructorTemplate);

      // in case the constructor was called without the new operator
      if (!localRef->HasInstance(info.This()))
      {
        if (info.Length() > 0)
        {
          std::unique_ptr<Local<Value> []> constructorArgs(new Local<Value>[info.Length()]);

          Local<Value> *argsPtr = constructorArgs.get();
          for (int i = 0; i < info.Length(); i++)
          {
            argsPtr[i] = info[i];
          }

		  MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), constructorArgs.get());
		  if (res.IsEmpty())
		  {
			  return;
		  }
		  info.GetReturnValue().Set(res.ToLocalChecked());
		  return;
		}
		else
		{
          MaybeLocal<Object> res = Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(), info.Length(), nullptr);
          if (res.IsEmpty())
          {
            return;
          }
          info.GetReturnValue().Set(res.ToLocalChecked());
          return;
        }
      }
      
      ::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ winRtInstance;


      if (info.Length() == 1 && OpaqueWrapper::IsOpaqueWrapper(info[0]) &&
        NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^>(info[0]))
      {
        try 
        {
          winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no suitable constructor found")));
	    	return;
      }

      NodeRT::Utils::SetHiddenValue(info.This(), Nan::New<String>("__winRtInstance__").ToLocalChecked(), True());

      PhoneLineChangedTriggerDetails *wrapperInstance = new PhoneLineChangedTriggerDetails(winRtInstance);
      wrapperInstance->Wrap(info.This());

      info.GetReturnValue().Set(info.This());
    }


	
    static void CastFrom(Nan::NAN_METHOD_ARGS_TYPE info)
    {
		HandleScope scope;
		if (info.Length() < 1 || !NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^>(info[0]))
		{
			Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Invalid arguments, no object provided, or given object could not be casted to requested type")));
			return;
		}

		::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ winRtInstance;
		try
		{
			winRtInstance = (::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^) NodeRT::Utils::GetObjectInstance(info[0]);
		}
		catch (Platform::Exception ^exception)
		{
			NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
			return;
		}

		info.GetReturnValue().Set(WrapPhoneLineChangedTriggerDetails(winRtInstance));
    }


  
    static void HasLinePropertyChanged(Nan::NAN_METHOD_ARGS_TYPE info)
    {
      HandleScope scope;

      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneLineChangedTriggerDetails *wrapper = PhoneLineChangedTriggerDetails::Unwrap<PhoneLineChangedTriggerDetails>(info.This());

      if (info.Length() == 1
        && info[0]->IsInt32())
      {
        try
        {
          ::Windows::ApplicationModel::Calls::Background::PhoneLineProperties arg0 = static_cast<::Windows::ApplicationModel::Calls::Background::PhoneLineProperties>(Nan::To<int32_t>(info[0]).FromMaybe(0));
          
          bool result;
          result = wrapper->_instance->HasLinePropertyChanged(arg0);
          info.GetReturnValue().Set(Nan::New<Boolean>(result));
          return;
        }
        catch (Platform::Exception ^exception)
        {
          NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
          return;
        }
      }
      else 
      {
        Nan::ThrowError(Nan::Error(NodeRT::Utils::NewString(L"Bad arguments: no suitable overload found")));
        return;
      }
    }



    static void ChangeTypeGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneLineChangedTriggerDetails *wrapper = PhoneLineChangedTriggerDetails::Unwrap<PhoneLineChangedTriggerDetails>(info.This());

      try 
      {
        ::Windows::ApplicationModel::Calls::Background::PhoneLineChangeKind result = wrapper->_instance->ChangeType;
        info.GetReturnValue().Set(Nan::New<Integer>(static_cast<int>(result)));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    
    static void LineIdGetter(Local<String> property, const Nan::PropertyCallbackInfo<v8::Value> &info)
    {
      HandleScope scope;
      
      if (!NodeRT::Utils::IsWinRtWrapperOf<::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^>(info.This()))
      {
        return;
      }

      PhoneLineChangedTriggerDetails *wrapper = PhoneLineChangedTriggerDetails::Unwrap<PhoneLineChangedTriggerDetails>(info.This());

      try 
      {
        ::Platform::Guid result = wrapper->_instance->LineId;
        info.GetReturnValue().Set(NodeRT::Utils::GuidToJs(result));
        return;
      }
      catch (Platform::Exception ^exception)
      {
        NodeRT::Utils::ThrowWinRtExceptionInJs(exception);
        return;
      }
    }
    


  private:
    ::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ _instance;
    static Persistent<FunctionTemplate> s_constructorTemplate;

    friend v8::Local<v8::Value> WrapPhoneLineChangedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ wintRtInstance);
    friend ::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ UnwrapPhoneLineChangedTriggerDetails(Local<Value> value);
  };
  Persistent<FunctionTemplate> PhoneLineChangedTriggerDetails::s_constructorTemplate;

  v8::Local<v8::Value> WrapPhoneLineChangedTriggerDetails(::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ winRtInstance)
  {
    EscapableHandleScope scope;

    if (winRtInstance == nullptr)
    {
      return scope.Escape(Undefined());
    }

    Local<Value> opaqueWrapper = CreateOpaqueWrapper(winRtInstance);
    Local<Value> args[] = {opaqueWrapper};
    Local<FunctionTemplate> localRef = Nan::New<FunctionTemplate>(PhoneLineChangedTriggerDetails::s_constructorTemplate);
    return scope.Escape(Nan::NewInstance(Nan::GetFunction(localRef).ToLocalChecked(),_countof(args), args).ToLocalChecked());
  }

  ::Windows::ApplicationModel::Calls::Background::PhoneLineChangedTriggerDetails^ UnwrapPhoneLineChangedTriggerDetails(Local<Value> value)
  {
     return PhoneLineChangedTriggerDetails::Unwrap<PhoneLineChangedTriggerDetails>(Nan::To<Object>(value).ToLocalChecked())->_instance;
  }

  void InitPhoneLineChangedTriggerDetails(Local<Object> exports)
  {
    PhoneLineChangedTriggerDetails::Init(exports);
  }

} } } } } 

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::Calls::Background::InitPhoneCallBlockedReasonEnum(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneTriggerTypeEnum(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneLineChangeKindEnum(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneLinePropertiesEnum(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneCallBlockedTriggerDetails(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneCallOriginDataRequestTriggerDetails(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneNewVoicemailMessageTriggerDetails(target);
  NodeRT::Windows::ApplicationModel::Calls::Background::InitPhoneLineChangedTriggerDetails(target);

  NodeRT::Utils::RegisterNameSpace("Windows.ApplicationModel.Calls.Background", target);
}


NODE_MODULE(binding, init)