// 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>

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

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

@end

@implementation DBUserTokenCppProxy

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

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

@end

namespace djinni_generated {

class UserToken::ObjcProxy final
: public ::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).cppRef.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<::UserToken>::getInstance()->get(cpp, [] (const CppType& p) {
        return [[DBUserTokenCppProxy alloc] initWithCpp:p];
    });
}

}  // namespace djinni_generated
