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

#import "DBMapListRecord+Private.h"
#import <Foundation/Foundation.h>
#include <utility>

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

@implementation DBMapListRecord

- (id)initWithMapListRecord:(DBMapListRecord *)mapListRecord
{
    if (self = [super init]) {
        _mapList = [NSMutableArray arrayWithCapacity:[mapListRecord.mapList count]];
        for (NSMutableDictionary *currentValue_0 in mapListRecord.mapList) {
            id copiedValue_0;
            copiedValue_0 = [NSMutableDictionary dictionaryWithCapacity:[currentValue_0 count]];
            for (id key_1 in currentValue_0) {
                id copiedKey_1, copiedValue_1;
                copiedKey_1 = [key_1 copy];
                id value_1 = [currentValue_0 objectForKey:key_1];
                copiedValue_1 = value_1;
                [copiedValue_0 setObject:copiedValue_1 forKey:copiedKey_1];
            }
            [_mapList addObject:copiedValue_0];
        }
    }
    return self;
}

- (id)initWithMapList:(NSMutableArray *)mapList
{
    if (self = [super init]) {
        _mapList = mapList;
    }
    return self;
}

- (id)initWithCppMapListRecord:(const MapListRecord &)mapListRecord
{
    if (self = [super init]) {
        _mapList = [NSMutableArray arrayWithCapacity:mapListRecord.map_list.size()];
        for (const auto & cppValue_0 : mapListRecord.map_list) {
            NSMutableDictionary *objcValue_0 = [NSMutableDictionary dictionaryWithCapacity:cppValue_0.size()];
            for (const auto & cppPair_1 : cppValue_0) {
                NSString *objcKey_1 = [[NSString alloc] initWithBytes:cppPair_1.first.data()
                        length:cppPair_1.first.length()
                        encoding:NSUTF8StringEncoding];
                NSNumber *objcValue_1 = [NSNumber numberWithLongLong:cppPair_1.second];
                [objcValue_0 setObject:objcValue_1 forKey:objcKey_1];
            }
            [_mapList addObject:objcValue_0];
        }
    }
    return self;
}

- (MapListRecord)cppMapListRecord
{
    std::vector<std::unordered_map<std::string, int64_t>> mapList;
    mapList.reserve([_mapList count]);
    for (NSMutableDictionary *objcValue_0 in _mapList) {
        std::unordered_map<std::string, int64_t> cppValue_0;
        for (id objcKey_1 in objcValue_0) {
            std::string cppKey_1([objcKey_1 UTF8String], [objcKey_1 lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
            int64_t cppValue_1 = [[objcValue_0 objectForKey:objcKey_1] longLongValue];
            cppValue_0.emplace(std::move(cppKey_1), std::move(cppValue_1));
        }
        mapList.push_back(std::move(cppValue_0));
    }
    return MapListRecord(
            std::move(mapList));
}

@end
