// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from test.djinni

#import "DBTestHelpers+Private.h"
#import "DBTestHelpers.h"
#import "DBAssortedIntegers+Private.h"
#import "DBClientInterface+Private.h"
#import "DBMapListRecord+Private.h"
#import "DBNestedCollection+Private.h"
#import "DBPrimitiveList+Private.h"
#import "DBSetRecord+Private.h"
#import "DBToken+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIDate.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#include <exception>
#include <utility>
#include <vector>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

@interface DBTestHelpers ()

@property (nonatomic, readonly) djinni::DbxCppWrapperCache<::TestHelpers>::Handle cppRef;

- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef;

@end

namespace djinni_generated {

auto TestHelpers::toCpp(ObjcType objc) -> CppType
{
    return objc ? objc.cppRef.get() : nullptr;
}

auto TestHelpers::fromCpp(const CppType& cpp) -> ObjcType
{
    return !cpp ? nil : djinni::DbxCppWrapperCache<::TestHelpers>::getInstance()->get(cpp, [] (const auto& p)
    {
        return [[DBTestHelpers alloc] initWithCpp:p];
    });
}

}  // namespace djinni_generated

@implementation DBTestHelpers

- (id)initWithCpp:(const std::shared_ptr<::TestHelpers>&)cppRef
{
    if (self = [super init]) {
        _cppRef.assign(cppRef);
    }
    return self;
}

+ (DBSetRecord *)getSetRecord {
    try {
        ::SetRecord cppRet = ::TestHelpers::get_set_record();
        DBSetRecord *objcRet = ::djinni_generated::SetRecord::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkSetRecord:(DBSetRecord *)rec {
    try {
        ::SetRecord cppRec = ::djinni_generated::SetRecord::toCpp(rec);
        bool cppRet = ::TestHelpers::check_set_record(std::move(cppRec));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBPrimitiveList *)getPrimitiveList {
    try {
        ::PrimitiveList cppRet = ::TestHelpers::get_primitive_list();
        DBPrimitiveList *objcRet = ::djinni_generated::PrimitiveList::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkPrimitiveList:(DBPrimitiveList *)pl {
    try {
        ::PrimitiveList cppPl = ::djinni_generated::PrimitiveList::toCpp(pl);
        bool cppRet = ::TestHelpers::check_primitive_list(std::move(cppPl));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBNestedCollection *)getNestedCollection {
    try {
        ::NestedCollection cppRet = ::TestHelpers::get_nested_collection();
        DBNestedCollection *objcRet = ::djinni_generated::NestedCollection::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkNestedCollection:(DBNestedCollection *)nc {
    try {
        ::NestedCollection cppNc = ::djinni_generated::NestedCollection::toCpp(nc);
        bool cppRet = ::TestHelpers::check_nested_collection(std::move(cppNc));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSDictionary *)getMap {
    try {
        std::unordered_map<std::string, int64_t> cppRet = ::TestHelpers::get_map();
        std::vector<NSString *> objcRetTempKeyVector;
        objcRetTempKeyVector.reserve(cppRet.size());
        std::vector<NSNumber *> objcRetTempValueVector;
        objcRetTempValueVector.reserve(cppRet.size());
        for (const auto & cppPair_0 : cppRet) {
            NSString *objcKey_0 = ::djinni::String::fromCpp(cppPair_0.first);
            NSNumber *objcValue_0 = ::djinni::I64::Boxed::fromCpp(cppPair_0.second);
            objcRetTempKeyVector.push_back(objcKey_0);
            objcRetTempValueVector.push_back(objcValue_0);
        }
        NSDictionary *objcRet = [NSDictionary dictionaryWithObjects:&objcRetTempValueVector[0] forKeys:&objcRetTempKeyVector[0] count:cppRet.size()];
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkMap:(NSDictionary *)m {
    try {
        std::unordered_map<std::string, int64_t> cppM;
        for (id objcKey_0 in m) {
            std::string cppKey_0 = ::djinni::String::toCpp(objcKey_0);
            int64_t cppValue_0 = ::djinni::I64::Boxed::toCpp([m objectForKey:objcKey_0]);
            cppM.emplace(std::move(cppKey_0), std::move(cppValue_0));
        }
        bool cppRet = ::TestHelpers::check_map(std::move(cppM));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSDictionary *)getEmptyMap {
    try {
        std::unordered_map<std::string, int64_t> cppRet = ::TestHelpers::get_empty_map();
        std::vector<NSString *> objcRetTempKeyVector;
        objcRetTempKeyVector.reserve(cppRet.size());
        std::vector<NSNumber *> objcRetTempValueVector;
        objcRetTempValueVector.reserve(cppRet.size());
        for (const auto & cppPair_0 : cppRet) {
            NSString *objcKey_0 = ::djinni::String::fromCpp(cppPair_0.first);
            NSNumber *objcValue_0 = ::djinni::I64::Boxed::fromCpp(cppPair_0.second);
            objcRetTempKeyVector.push_back(objcKey_0);
            objcRetTempValueVector.push_back(objcValue_0);
        }
        NSDictionary *objcRet = [NSDictionary dictionaryWithObjects:&objcRetTempValueVector[0] forKeys:&objcRetTempKeyVector[0] count:cppRet.size()];
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkEmptyMap:(NSDictionary *)m {
    try {
        std::unordered_map<std::string, int64_t> cppM;
        for (id objcKey_0 in m) {
            std::string cppKey_0 = ::djinni::String::toCpp(objcKey_0);
            int64_t cppValue_0 = ::djinni::I64::Boxed::toCpp([m objectForKey:objcKey_0]);
            cppM.emplace(std::move(cppKey_0), std::move(cppValue_0));
        }
        bool cppRet = ::TestHelpers::check_empty_map(std::move(cppM));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBMapListRecord *)getMapListRecord {
    try {
        ::MapListRecord cppRet = ::TestHelpers::get_map_list_record();
        DBMapListRecord *objcRet = ::djinni_generated::MapListRecord::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (BOOL)checkMapListRecord:(DBMapListRecord *)m {
    try {
        ::MapListRecord cppM = ::djinni_generated::MapListRecord::toCpp(m);
        bool cppRet = ::TestHelpers::check_map_list_record(std::move(cppM));
        BOOL objcRet = ::djinni::Bool::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (void)checkClientInterfaceAscii:(id<DBClientInterface>)i {
    try {
        std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterface::toCpp(i);
        ::TestHelpers::check_client_interface_ascii(std::move(cppI));
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (void)checkClientInterfaceNonascii:(id<DBClientInterface>)i {
    try {
        std::shared_ptr<::ClientInterface> cppI = ::djinni_generated::ClientInterface::toCpp(i);
        ::TestHelpers::check_client_interface_nonascii(std::move(cppI));
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (void)checkEnumMap:(NSDictionary *)m {
    try {
        std::unordered_map<::color, std::string> cppM;
        for (id objcKey_0 in m) {
            ::color cppKey_0 = ::djinni::Enum<::color, DBColor>::Boxed::toCpp(objcKey_0);
            std::string cppValue_0 = ::djinni::String::toCpp([m objectForKey:objcKey_0]);
            cppM.emplace(std::move(cppKey_0), std::move(cppValue_0));
        }
        ::TestHelpers::check_enum_map(std::move(cppM));
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBToken *)tokenId:(DBToken *)t {
    try {
        std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
        std::shared_ptr<::Token> cppRet = ::TestHelpers::token_id(std::move(cppT));
        DBToken* objcRet = ::djinni_generated::Token::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBToken *)createCppToken {
    try {
        std::shared_ptr<::Token> cppRet = ::TestHelpers::create_cpp_token();
        DBToken* objcRet = ::djinni_generated::Token::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (void)checkCppToken:(DBToken *)t {
    try {
        std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
        ::TestHelpers::check_cpp_token(std::move(cppT));
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (int64_t)cppTokenId:(DBToken *)t {
    try {
        std::shared_ptr<::Token> cppT = ::djinni_generated::Token::toCpp(t);
        int64_t cppRet = ::TestHelpers::cpp_token_id(std::move(cppT));
        int64_t objcRet = ::djinni::I64::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSNumber *)returnNone {
    try {
        std::experimental::optional<int32_t> cppRet = ::TestHelpers::return_none();
        NSNumber *objcRet;
        if (cppRet) {
            objcRet = ::djinni::I32::Boxed::fromCpp((*(cppRet)));
        } else {
            objcRet = nil;
        }
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (DBAssortedIntegers *)assortedIntegersId:(DBAssortedIntegers *)i {
    try {
        ::AssortedIntegers cppI = ::djinni_generated::AssortedIntegers::toCpp(i);
        ::AssortedIntegers cppRet = ::TestHelpers::assorted_integers_id(std::move(cppI));
        DBAssortedIntegers *objcRet = ::djinni_generated::AssortedIntegers::fromCpp(cppRet);
        return objcRet;
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

@end
