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

#import "DBExternInterface1+Private.h"
#import "DBExternInterface1.h"
#import "DBClientInterface+Private.h"
#import "DBClientReturnedRecord+Private.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#include <exception>
#include <utility>

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

@interface DBExternInterface1 ()

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

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

@end

@implementation DBExternInterface1

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

- (nonnull DBClientReturnedRecord *)foo:(nullable id<DBClientInterface>)i {
    try {
        auto r = _cppRef.get()->foo(::djinni_generated::ClientInterface::toCpp(i));
        return ::djinni_generated::ClientReturnedRecord::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

@end

namespace djinni_generated {

auto ExternInterface1::toCpp(ObjcType objc) -> CppType
{
    if (!objc) {
        return nullptr;
    }
    return objc.cppRef.get();
}

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

}  // namespace djinni_generated
