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

#import "DBMapRecord+Private.h"
#import "DJIDate.h"
#import <Foundation/Foundation.h>
#include <utility>
#include <vector>

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

@implementation DBMapRecord

- (id)initWithMapRecord:(DBMapRecord *)mapRecord
{
    if (self = [super init]) {
        std::vector<NSString *> _mapTempKeyVector;
        _mapTempKeyVector.reserve([mapRecord.map count]);
        std::vector<NSNumber *> _mapTempValueVector;
        _mapTempValueVector.reserve([mapRecord.map count]);
        for (NSString *key_0 in mapRecord.map) {
            NSNumber *copiedValue_0;
            _mapTempKeyVector.push_back(key_0);
            NSNumber *value_0 = [mapRecord.map objectForKey:key_0];
            copiedValue_0 = value_0;
            _mapTempValueVector.push_back(copiedValue_0);
        }
        _map = [NSDictionary dictionaryWithObjects:&_mapTempValueVector[0] forKeys:&_mapTempKeyVector[0] count:[mapRecord.map count]];
    }
    return self;
}

- (id)initWithMap:(NSDictionary *)map
{
    if (self = [super init]) {
        _map = map;
    }
    return self;
}

- (id)initWithCppMapRecord:(const MapRecord &)mapRecord
{
    if (self = [super init]) {
        std::vector<NSString *> _mapTempKeyVector;
        _mapTempKeyVector.reserve(mapRecord.map.size());
        std::vector<NSNumber *> _mapTempValueVector;
        _mapTempValueVector.reserve(mapRecord.map.size());
        for (const auto & cppPair_0 : mapRecord.map) {
            NSString *objcKey_0 = [[NSString alloc] initWithBytes:cppPair_0.first.data()
                    length:cppPair_0.first.length()
                    encoding:NSUTF8StringEncoding];
            NSNumber *objcValue_0 = [NSNumber numberWithLongLong:cppPair_0.second];
            _mapTempKeyVector.push_back(objcKey_0);
            _mapTempValueVector.push_back(objcValue_0);
        }
        _map = [NSDictionary dictionaryWithObjects:&_mapTempValueVector[0] forKeys:&_mapTempKeyVector[0] count:mapRecord.map.size()];
    }
    return self;
}

- (MapRecord)cppMapRecord
{
    std::unordered_map<std::string, int64_t> map;
    for (id objcKey_0 in _map) {
        std::string cppKey_0([objcKey_0 UTF8String], [objcKey_0 lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
        int64_t cppValue_0 = [[_map objectForKey:objcKey_0] longLongValue];
        map.emplace(std::move(cppKey_0), std::move(cppValue_0));
    }
    return MapRecord(
            std::move(map));
}

@end
