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

#import "DBTestDuration+Private.h"
#import "DBTestDuration.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "Duration-objc.hpp"
#include <exception>
#include <utility>

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

@interface DBTestDuration ()

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

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

@end

@implementation DBTestDuration

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

+ (nonnull NSString *)hoursString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::hoursString(::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull NSString *)minutesString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::minutesString(::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull NSString *)secondsString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::secondsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull NSString *)millisString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::millisString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull NSString *)microsString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::microsString(::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull NSString *)nanosString:(NSTimeInterval)dt {
    try {
        auto r = ::TestDuration::nanosString(::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::toCpp(dt));
        return ::djinni::String::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)hours:(int32_t)count {
    try {
        auto r = ::TestDuration::hours(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_h>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)minutes:(int32_t)count {
    try {
        auto r = ::TestDuration::minutes(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_min>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)seconds:(int32_t)count {
    try {
        auto r = ::TestDuration::seconds(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_s>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)millis:(int32_t)count {
    try {
        auto r = ::TestDuration::millis(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ms>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)micros:(int32_t)count {
    try {
        auto r = ::TestDuration::micros(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_us>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)nanos:(int32_t)count {
    try {
        auto r = ::TestDuration::nanos(::djinni::I32::toCpp(count));
        return ::djinni::Duration<::djinni::I32, ::djinni::Duration_ns>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)hoursf:(double)count {
    try {
        auto r = ::TestDuration::hoursf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_h>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)minutesf:(double)count {
    try {
        auto r = ::TestDuration::minutesf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_min>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)secondsf:(double)count {
    try {
        auto r = ::TestDuration::secondsf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_s>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)millisf:(double)count {
    try {
        auto r = ::TestDuration::millisf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ms>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)microsf:(double)count {
    try {
        auto r = ::TestDuration::microsf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_us>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (NSTimeInterval)nanosf:(double)count {
    try {
        auto r = ::TestDuration::nanosf(::djinni::F64::toCpp(count));
        return ::djinni::Duration<::djinni::F64, ::djinni::Duration_ns>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nullable NSNumber *)box:(int64_t)count {
    try {
        auto r = ::TestDuration::box(::djinni::I64::toCpp(count));
        return ::djinni::Optional<std::experimental::optional, ::djinni::Duration<::djinni::I64, ::djinni::Duration_s>>::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (int64_t)unbox:(nullable NSNumber *)dt {
    try {
        auto r = ::TestDuration::unbox(::djinni::Optional<std::experimental::optional, ::djinni::Duration<::djinni::I64, ::djinni::Duration_s>>::toCpp(dt));
        return ::djinni::I64::fromCpp(r);
    } DJINNI_TRANSLATE_EXCEPTIONS()
}

@end

namespace djinni_generated {

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

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

}  // namespace djinni_generated
