// 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::CppProxyCache::Handle<std::shared_ptr<::testsuite::UserToken>> _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::ObjcProxyCache::Handle<ObjcType>
{
public:
    using Handle::Handle;
    std::string whoami() override
    {
        @autoreleasepool {
            auto r = [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::get_objc_proxy<ObjcProxy>(objc);
}

auto UserToken::fromCppOpt(const CppOptType& cpp) -> ObjcType
{
    if (!cpp) {
        return nil;
    }
    if (auto cppPtr = dynamic_cast<ObjcProxy*>(cpp.get())) {
        return cppPtr->Handle::get();
    }
    return ::djinni::get_cpp_proxy<DBUserTokenCppProxy>(cpp);
}

}  // namespace djinni_generated

@end
