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

#import "DBUserToken+Private.h"
#import "DBUserToken.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "DJIObjcWrapperCache+Private.h"
#include <exception>
#include <utility>

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

@interface DBUserTokenCppProxy : NSObject<DBUserToken>

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

@end

@implementation DBUserTokenCppProxy {
    ::djinni::DbxCppWrapperCache<::testsuite::UserToken>::Handle _cppRefHandle;
}

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

- (nonnull NSString *)whoami {
    try {
        auto r = _cppRefHandle.get()->whoami();
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

namespace djinni_generated {

class UserToken::ObjcProxy final
: public ::testsuite::UserToken
, public ::djinni::DbxObjcWrapperCache<ObjcProxy>::Handle
{
public:
    using Handle::Handle;
    std::string whoami() override
    {
        @autoreleasepool {
            auto r = [(ObjcType)Handle::get() whoami];
            return ::djinni::String::toCpp(r);
        }
    }
};

}  // namespace djinni_generated

namespace djinni_generated {

auto UserToken::toCpp(ObjcType objc) -> CppType
{
    if (!objc) {
        return nullptr;
    }
    if ([(id)objc isKindOfClass:[DBUserTokenCppProxy class]]) {
        return ((DBUserTokenCppProxy*)objc)->_cppRefHandle.get();
    }
    return ::djinni::DbxObjcWrapperCache<ObjcProxy>::getInstance()->get(objc);
}

auto UserToken::fromCpp(const CppType& cpp) -> ObjcType
{
    if (!cpp) {
        return nil;
    }
    if (auto cppPtr = dynamic_cast<ObjcProxy*>(cpp.get())) {
        return cppPtr->Handle::get();
    }
    return ::djinni::DbxCppWrapperCache<::testsuite::UserToken>::getInstance()->get(cpp, [] (const CppType& p) {
        return [[DBUserTokenCppProxy alloc] initWithCpp:p];
    });
}

}  // namespace djinni_generated

@end
