rsmgclient 3.0.0

Memgraph database adapter for Rust programming language.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
// Copyright (c) 2016-2020 Memgraph Ltd. [https://memgraph.com]
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <cstring>
#include <initializer_list>
#include <set>
#include <stdexcept>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "mgclient.h"

namespace mg {

namespace detail {
// uint to int conversion in C++ is a bit tricky. Take a look here
// https://stackoverflow.com/questions/14623266/why-cant-i-reinterpret-cast-uint-to-int
// for more details.
template <typename TDest, typename TSrc>
TDest MemcpyCast(TSrc src) {
  TDest dest;
  static_assert(sizeof(dest) == sizeof(src),
                "MemcpyCast expects source and destination to be of same size");
  static_assert(std::is_arithmetic<TSrc>::value,
                "MemcpyCast expects source is an arithmetic type");
  static_assert(std::is_arithmetic<TDest>::value,
                "MemcpyCast expects destination is an arithmetic type");
  std::memcpy(&dest, &src, sizeof(src));
  return dest;
}

}  // namespace detail

// Forward declarations:
class ConstList;
class ConstMap;
class ConstNode;
class ConstRelationship;
class ConstUnboundRelationship;
class ConstPath;
class ConstDate;
class ConstTime;
class ConstLocalTime;
class ConstDateTime;
class ConstDateTimeZoneId;
class ConstLocalDateTime;
class ConstDuration;
class ConstPoint2d;
class ConstPoint3d;
class ConstValue;
class Value;

#define CREATE_ITERATOR(container, element)                                    \
  class Iterator {                                                             \
   private:                                                                    \
    friend class container;                                                    \
                                                                               \
   public:                                                                     \
    bool operator==(const Iterator &other) const {                             \
      return iterable_ == other.iterable_ && index_ == other.index_;           \
    }                                                                          \
                                                                               \
    bool operator!=(const Iterator &other) const { return !(*this == other); } \
                                                                               \
    Iterator &operator++() {                                                   \
      index_++;                                                                \
      return *this;                                                            \
    }                                                                          \
                                                                               \
    element operator*() const;                                                 \
                                                                               \
   private:                                                                    \
    Iterator(const container *iterable, size_t index)                          \
        : iterable_(iterable), index_(index) {}                                \
                                                                               \
    const container *iterable_;                                                \
    size_t index_;                                                             \
  }

/// Wrapper for int64_t ID to prevent dangerous implicit conversions.
class Id {
 public:
  Id() = default;

  /// Construct Id from uint64_t
  static Id FromUint(uint64_t id) {
    return Id(detail::MemcpyCast<int64_t>(id));
  }

  /// Construct Id from int64_t
  static Id FromInt(int64_t id) { return Id(id); }

  int64_t AsInt() const { return id_; }
  uint64_t AsUint() const { return detail::MemcpyCast<uint64_t>(id_); }

  bool operator==(const Id &other) const { return id_ == other.id_; }
  bool operator!=(const Id &other) const { return !(*this == other); }

 private:
  explicit Id(int64_t id) : id_(id) {}

  int64_t id_;
};

////////////////////////////////////////////////////////////////////////////////
/// List:

/// \brief Wrapper class for \ref mg_list.
class List final {
 private:
  friend class Value;

 public:
  CREATE_ITERATOR(List, ConstValue);

  explicit List(mg_list *ptr) : ptr_(ptr) {}

  /// \brief Create a List from a copy of the given \ref mg_list.
  explicit List(const mg_list *const_ptr) : List(mg_list_copy(const_ptr)) {}

  List(const List &other);
  List(List &&other);
  List &operator=(const List &other) = delete;
  List &operator=(List &&other) = delete;

  ~List();

  /// \brief Create a new list by copying the ConstList.
  explicit List(const ConstList &list);

  /// \brief Constructs a list that can hold at most \p capacity elements.
  /// \param capacity The maximum number of elements that the newly constructed
  ///                 list can hold.
  explicit List(size_t capacity) : List(mg_list_make_empty(capacity)) {}

  explicit List(const std::vector<mg::Value> &values);

  explicit List(std::vector<mg::Value> &&values);

  List(std::initializer_list<Value> list);

  size_t size() const { return mg_list_size(ptr_); }

  bool empty() const { return size() == 0; }

  /// \brief Returns the value at the given `index`.
  const ConstValue operator[](size_t index) const;

  Iterator begin() const { return Iterator(this, 0); }
  Iterator end() const { return Iterator(this, size()); }

  /// \brief Appends the given `value` to the list.
  /// The `value` is copied.
  bool Append(const Value &value);

  /// \brief Appends the given `value` to the list.
  /// The `value` is copied.
  bool Append(const ConstValue &value);

  /// \brief Appends the given `value` to the list.
  /// \note
  /// It takes the ownership of the `value` by moving it.
  /// Behaviour of accessing the `value` after performing this operation is
  /// considered undefined.
  bool Append(Value &&value);

  const ConstList AsConstList() const;

  /// \exception std::runtime_error list contains value with unknown type
  bool operator==(const List &other) const;
  /// \exception std::runtime_error list contains value with unknown type
  bool operator==(const ConstList &other) const;
  /// \exception std::runtime_error list contains value with unknown type
  bool operator!=(const List &other) const { return !(*this == other); }
  /// \exception std::runtime_error list contains value with unknown type
  bool operator!=(const ConstList &other) const { return !(*this == other); }

  const mg_list *ptr() const { return ptr_; }

 private:
  mg_list *ptr_;
};

class ConstList final {
 public:
  CREATE_ITERATOR(ConstList, ConstValue);

  explicit ConstList(const mg_list *const_ptr) : const_ptr_(const_ptr) {}

  size_t size() const { return mg_list_size(const_ptr_); }
  bool empty() const { return size() == 0; }

  /// \brief Returns the value at the given `index`.
  const ConstValue operator[](size_t index) const;

  Iterator begin() const { return Iterator(this, 0); }
  Iterator end() const { return Iterator(this, size()); }

  /// \exception std::runtime_error list contains value with unknown type
  bool operator==(const ConstList &other) const;
  /// \exception std::runtime_error list contains value with unknown type
  bool operator==(const List &other) const;
  /// \exception std::runtime_error list contains value with unknown type
  bool operator!=(const ConstList &other) const { return !(*this == other); }
  /// \exception std::runtime_error list contains value with unknown type
  bool operator!=(const List &other) const { return !(*this == other); }

  const mg_list *ptr() const { return const_ptr_; }

 private:
  const mg_list *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Map:

/// \brief Wrapper class for \ref mg_map.
class Map final {
 private:
  friend class Value;
  using KeyValuePair = std::pair<std::string_view, ConstValue>;

 public:
  CREATE_ITERATOR(Map, KeyValuePair);

  explicit Map(mg_map *ptr) : ptr_(ptr) {}

  /// \brief Create a Map from a copy of the given \ref mg_map.
  explicit Map(const mg_map *const_ptr) : Map(mg_map_copy(const_ptr)) {}

  Map(const Map &other);
  Map(Map &&other);
  Map &operator=(const Map &other) = delete;
  Map &operator=(Map &&other) = delete;
  ~Map();

  /// Copies content of the given `map`.
  explicit Map(const ConstMap &map);

  /// \brief Constructs an empty Map that can hold at most \p capacity key-value
  /// pairs.
  ///
  /// Key-value pairs should be constructed and then inserted using
  /// \ref Insert, \ref InsertUnsafe and similar.
  ///
  /// \param capacity The maximum number of key-value pairs that the newly
  ///                 constructed Map can hold.
  explicit Map(size_t capacity) : Map(mg_map_make_empty(capacity)) {}

  /// \brief Constructs an map from the list of key-value pairs.
  /// Values are copied.
  Map(std::initializer_list<std::pair<std::string, Value>> list);

  size_t size() const { return mg_map_size(ptr_); }

  bool empty() const { return size() == 0; }

  /// \brief Returns the value associated with the given `key`.
  /// Behaves undefined if there is no such a value.
  /// \note
  /// Each key-value pair has to be checked, resulting with
  /// O(n) time complexity.
  ConstValue operator[](const std::string_view key) const;

  Iterator begin() const { return Iterator(this, 0); }
  Iterator end() const { return Iterator(this, size()); }

  /// \brief Returns the key-value iterator for the given `key`.
  /// In the case there is no such pair, `end` iterator is returned.
  /// \note
  /// Each key-value pair has to be checked, resulting with O(n) time
  /// complexity.
  Iterator find(const std::string_view key) const;

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// Checks if the given `key` already exists by iterating over all entries.
  /// Copies both the `key` and the `value`.
  bool Insert(const std::string_view key, const Value &value);

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// Checks if the given `key` already exists by iterating over all entries.
  /// Copies both the `key` and the `value`.
  bool Insert(const std::string_view key, const ConstValue &value);

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// Checks if the given `key` already exists by iterating over all entries.
  /// Copies the `key` and takes the ownership of `value` by moving it.
  /// Behaviour of accessing the `value` after performing this operation is
  /// considered undefined.
  bool Insert(const std::string_view key, Value &&value);

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// It doesn't check if the given `key` already exists in the map.
  /// Copies both the `key` and the `value`.
  bool InsertUnsafe(const std::string_view key, const Value &value);

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// It doesn't check if the  given `key` already exists in the map.
  /// Copies both the `key` and the `value`.
  bool InsertUnsafe(const std::string_view key, const ConstValue &value);

  /// \brief Inserts the given `key`-`value` pair into the map.
  /// It doesn't check if the given `key` already exists in the map.
  /// Copies the `key` and takes the ownership of `value` by moving it.
  /// Behaviour of accessing the `value` after performing this operation
  /// is considered undefined.
  bool InsertUnsafe(const std::string_view key, Value &&value);

  const ConstMap AsConstMap() const;

  /// \exception std::runtime_error map contains value with unknown type
  bool operator==(const Map &other) const;
  /// \exception std::runtime_error map contains value with unknown type
  bool operator==(const ConstMap &other) const;
  /// \exception std::runtime_error map contains value with unknown type
  bool operator!=(const Map &other) const { return !(*this == other); }
  /// \exception std::runtime_error map contains value with unknown type
  bool operator!=(const ConstMap &other) const { return !(*this == other); }

  const mg_map *ptr() const { return ptr_; }

 private:
  mg_map *ptr_;
};

class ConstMap final {
 private:
  using KeyValuePair = std::pair<std::string_view, ConstValue>;

 public:
  CREATE_ITERATOR(ConstMap, KeyValuePair);

  explicit ConstMap(const mg_map *const_ptr) : const_ptr_(const_ptr) {}

  size_t size() const { return mg_map_size(const_ptr_); }

  bool empty() const { return size() == 0; }

  /// \brief Returns the value associated with the given `key`.
  /// Behaves undefined if there is no such a value.
  /// \note
  /// Each key-value pair has to be checked, resulting with O(n)
  /// time complexity.
  ConstValue operator[](const std::string_view key) const;

  Iterator begin() const { return Iterator(this, 0); }
  Iterator end() const { return Iterator(this, size()); }

  /// \brief Returns the key-value iterator for the given `key`.
  /// In the case there is no such pair, end iterator is returned.
  /// \note
  /// Each key-value pair has to be checked, resulting with O(n) time
  /// complexity.
  Iterator find(const std::string_view key) const;

  /// \exception std::runtime_error map contains value with unknown type
  bool operator==(const ConstMap &other) const;
  /// \exception std::runtime_error map contains value with unknown type
  bool operator==(const Map &other) const;
  /// \exception std::runtime_error map contains value with unknown type
  bool operator!=(const ConstMap &other) const { return !(*this == other); }
  /// \exception std::runtime_error map contains value with unknown type
  bool operator!=(const Map &other) const { return !(*this == other); }

  const mg_map *ptr() const { return const_ptr_; }

 private:
  const mg_map *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Node:

/// \brief Wrapper class for \ref mg_node
class Node final {
 private:
  friend class Value;

 public:
  /// \brief View of the node's labels
  class Labels final {
   public:
    CREATE_ITERATOR(Labels, std::string_view);

    explicit Labels(const mg_node *node) : node_(node) {}

    size_t size() const { return mg_node_label_count(node_); }

    /// \brief Return node's label at the `index` position.
    std::string_view operator[](size_t index) const;

    Iterator begin() { return Iterator(this, 0); }
    Iterator end() { return Iterator(this, size()); }

   private:
    const mg_node *node_;
  };

  explicit Node(mg_node *ptr) : ptr_(ptr) {}

  /// \brief Create a Node from a copy of the given \ref mg_node.
  explicit Node(const mg_node *const_ptr) : Node(mg_node_copy(const_ptr)) {}

  Node(const Node &other);
  Node(Node &&other);
  Node &operator=(const Node &other) = delete;
  Node &operator=(Node &&other) = delete;
  ~Node();

  explicit Node(const ConstNode &node);

  Id id() const { return Id::FromInt(mg_node_id(ptr_)); }

  Labels labels() const { return Labels(ptr_); }

  ConstMap properties() const { return ConstMap(mg_node_properties(ptr_)); }

  ConstNode AsConstNode() const;

  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator==(const Node &other) const;
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator==(const ConstNode &other) const;
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator!=(const Node &other) const { return !(*this == other); }
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator!=(const ConstNode &other) const { return !(*this == other); }

  const mg_node *ptr() const { return ptr_; }

 private:
  mg_node *ptr_;
};

class ConstNode final {
 public:
  explicit ConstNode(const mg_node *const_ptr) : const_ptr_(const_ptr) {}

  Id id() const { return Id::FromInt(mg_node_id(const_ptr_)); }

  Node::Labels labels() const { return Node::Labels(const_ptr_); }

  ConstMap properties() const {
    return ConstMap(mg_node_properties(const_ptr_));
  }

  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator==(const ConstNode &other) const;
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator==(const Node &other) const;
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator!=(const ConstNode &other) const { return !(*this == other); }
  /// \exception std::runtime_error node property contains value with
  /// unknown type
  bool operator!=(const Node &other) const { return !(*this == other); }

  const mg_node *ptr() const { return const_ptr_; }

 private:
  const mg_node *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Relationship:

/// \brief Wrapper class for \ref mg_relationship.
class Relationship final {
 private:
  friend class Value;

 public:
  explicit Relationship(mg_relationship *ptr) : ptr_(ptr) {}

  /// \brief Create a Relationship from a copy the given \ref mg_relationship.
  explicit Relationship(const mg_relationship *const_ptr)
      : Relationship(mg_relationship_copy(const_ptr)) {}

  Relationship(const Relationship &other);
  Relationship(Relationship &&other);
  Relationship &operator=(const Relationship &other) = delete;
  Relationship &operator=(Relationship &&other) = delete;
  ~Relationship();

  explicit Relationship(const ConstRelationship &rel);

  Id id() const { return Id::FromInt(mg_relationship_id(ptr_)); }

  /// \brief Return the Id of the node that is at the start of the relationship.
  Id from() const { return Id::FromInt(mg_relationship_start_id(ptr_)); }

  /// \brief Return the Id of the node that is at the end of the relationship.
  Id to() const { return Id::FromInt(mg_relationship_end_id(ptr_)); }

  std::string_view type() const;

  ConstMap properties() const {
    return ConstMap(mg_relationship_properties(ptr_));
  }

  ConstRelationship AsConstRelationship() const;

  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const Relationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const ConstRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const Relationship &other) const { return !(*this == other); }
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const ConstRelationship &other) const {
    return !(*this == other);
  }

  const mg_relationship *ptr() const { return ptr_; }

 private:
  mg_relationship *ptr_;
};

class ConstRelationship final {
 public:
  explicit ConstRelationship(const mg_relationship *const_ptr)
      : const_ptr_(const_ptr) {}

  Id id() const { return Id::FromInt(mg_relationship_id(const_ptr_)); }

  /// \brief Return the Id of the node that is at the start of the relationship.
  Id from() const { return Id::FromInt(mg_relationship_start_id(const_ptr_)); }

  /// \brief Return the Id of the node that is at the end of the relationship.
  Id to() const { return Id::FromInt(mg_relationship_end_id(const_ptr_)); }

  std::string_view type() const;

  ConstMap properties() const {
    return ConstMap(mg_relationship_properties(const_ptr_));
  }

  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const ConstRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const Relationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const ConstRelationship &other) const {
    return !(*this == other);
  }
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const Relationship &other) const { return !(*this == other); }

  const mg_relationship *ptr() const { return const_ptr_; }

 private:
  const mg_relationship *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// UnboundRelationship:

/// \brief Wrapper class for \ref mg_unbound_relationship.
class UnboundRelationship final {
 private:
  friend class Value;

 public:
  explicit UnboundRelationship(mg_unbound_relationship *ptr) : ptr_(ptr) {}

  /// \brief Create an UnboundRelationship from a copy of the given
  /// \ref mg_unbound_relationship.
  explicit UnboundRelationship(const mg_unbound_relationship *const_ptr)
      : UnboundRelationship(mg_unbound_relationship_copy(const_ptr)) {}

  UnboundRelationship(const UnboundRelationship &other);
  UnboundRelationship(UnboundRelationship &&other);
  UnboundRelationship &operator=(const UnboundRelationship &other) = delete;
  UnboundRelationship &operator=(UnboundRelationship &&other) = delete;
  ~UnboundRelationship();

  explicit UnboundRelationship(const ConstUnboundRelationship &rel);

  Id id() const { return Id::FromInt(mg_unbound_relationship_id(ptr_)); }

  std::string_view type() const;

  ConstMap properties() const {
    return ConstMap(mg_unbound_relationship_properties(ptr_));
  }

  ConstUnboundRelationship AsConstUnboundRelationship() const;

  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const UnboundRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const ConstUnboundRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const UnboundRelationship &other) const {
    return !(*this == other);
  }
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const ConstUnboundRelationship &other) const {
    return !(*this == other);
  }

  const mg_unbound_relationship *ptr() const { return ptr_; }

 private:
  mg_unbound_relationship *ptr_;
};

class ConstUnboundRelationship final {
 public:
  explicit ConstUnboundRelationship(const mg_unbound_relationship *const_ptr)
      : const_ptr_(const_ptr) {}

  Id id() const { return Id::FromInt(mg_unbound_relationship_id(const_ptr_)); }

  std::string_view type() const;

  ConstMap properties() const {
    return ConstMap(mg_unbound_relationship_properties(const_ptr_));
  }

  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const ConstUnboundRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator==(const UnboundRelationship &other) const;
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const ConstUnboundRelationship &other) const {
    return !(*this == other);
  }
  /// \exception std::runtime_error relationship property contains value with
  /// unknown type
  bool operator!=(const UnboundRelationship &other) const {
    return !(*this == other);
  }

  const mg_unbound_relationship *ptr() const { return const_ptr_; }

 private:
  const mg_unbound_relationship *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Path:

/// \brief Wrapper class for \ref mg_path.
class Path final {
 private:
  friend class Value;

 public:
  explicit Path(mg_path *ptr) : ptr_(ptr) {}

  /// \brief Create a Path from a copy of the given \ref mg_path.
  explicit Path(const mg_path *const_ptr) : Path(mg_path_copy(const_ptr)) {}

  Path(const Path &other);
  Path(Path &&other);
  Path &operator=(const Path &other);
  Path &operator=(Path &&other);
  ~Path();

  explicit Path(const ConstPath &path);

  /// Length of the path is number of edges.
  size_t length() const { return mg_path_length(ptr_); }

  /// \brief Returns the vertex at the given `index`.
  /// \pre `index` should be less than or equal to length of the path.
  ConstNode GetNodeAt(size_t index) const;

  /// \brief Returns the edge at the given `index`.
  /// \pre `index` should be less than length of the path.
  ConstUnboundRelationship GetRelationshipAt(size_t index) const;

  /// \brief Returns the orientation of the edge at the given `index`.
  /// \pre `index` should be less than length of the path.
  /// \return True if the edge is reversed, false otherwise.
  bool IsReversedRelationshipAt(size_t index) const;

  ConstPath AsConstPath() const;

  /// \exception std::runtime_error path contains elements with unknown value
  bool operator==(const Path &other) const;
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator==(const ConstPath &other) const;
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator!=(const Path &other) const { return !(*this == other); }
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator!=(const ConstPath &other) const { return !(*this == other); }

  const mg_path *ptr() const { return ptr_; }

 private:
  mg_path *ptr_;
};

class ConstPath final {
 public:
  explicit ConstPath(const mg_path *const_ptr) : const_ptr_(const_ptr) {}

  /// Length of the path in number of edges.
  size_t length() const { return mg_path_length(const_ptr_); }

  /// \brief Returns the vertex at the given `index`.
  /// \pre `index` should be less than or equal to length of the path.
  ConstNode GetNodeAt(size_t index) const;

  /// \brief Returns the edge at the given `index`.
  /// \pre `index` should be less than length of the path.
  ConstUnboundRelationship GetRelationshipAt(size_t index) const;

  /// \brief Returns the orientation of the edge at the given `index`.
  /// \pre `index` should be less than length of the path.
  /// \return True if the edge is reversed, false otherwise.
  bool IsReversedRelationshipAt(size_t index) const;

  /// \exception std::runtime_error path contains elements with unknown value
  bool operator==(const ConstPath &other) const;
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator==(const Path &other) const;
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator!=(const ConstPath &other) const { return !(*this == other); }
  /// \exception std::runtime_error path contains elements with unknown value
  bool operator!=(const Path &other) const { return !(*this == other); }

  const mg_path *ptr() const { return const_ptr_; }

 private:
  const mg_path *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Date:

/// \brief Wrapper class for \ref mg_date
class Date final {
 private:
  friend class Value;

 public:
  explicit Date(mg_date *ptr) : ptr_(ptr) {}

  explicit Date(const mg_date *const_ptr) : Date(mg_date_copy(const_ptr)) {}

  Date(const Date &other);
  Date(Date &&other);
  Date &operator=(const Date &other);
  Date &operator=(Date &&other);
  ~Date();

  explicit Date(const ConstDate &date);

  /// \brief Returns days since Unix epoch.
  int64_t days() const { return mg_date_days(ptr_); }

  ConstDate AsConstDate() const;

  bool operator==(const Date &other) const;
  bool operator==(const ConstDate &other) const;
  bool operator!=(const Date &other) const { return !(*this == other); }
  bool operator!=(const ConstDate &other) const { return !(*this == other); }

  const mg_date *ptr() const { return ptr_; }

 private:
  mg_date *ptr_;
};

class ConstDate final {
 public:
  explicit ConstDate(const mg_date *const_ptr) : const_ptr_(const_ptr) {}

  /// \brief Returns days since Unix epoch.
  int64_t days() const { return mg_date_days(const_ptr_); }

  bool operator==(const ConstDate &other) const;
  bool operator==(const Date &other) const;
  bool operator!=(const ConstDate &other) const { return !(*this == other); }
  bool operator!=(const Date &other) const { return !(*this == other); }

  const mg_date *ptr() const { return const_ptr_; };

 private:
  const mg_date *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Time:

/// \brief Wrapper class for \ref mg_time
class Time final {
 private:
  friend class Value;

 public:
  explicit Time(mg_time *ptr) : ptr_(ptr) {}

  explicit Time(const mg_time *const_ptr) : Time(mg_time_copy(const_ptr)) {}

  Time(const Time &other);
  Time(Time &&other);
  Time &operator=(const Time &other);
  Time &operator=(Time &&other);
  ~Time();

  explicit Time(const ConstTime &time);

  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_time_nanoseconds(ptr_); }
  /// Returns time zone offset in seconds from UTC.
  int64_t tz_offset_seconds() const { return mg_time_tz_offset_seconds(ptr_); }

  ConstTime AsConstTime() const;

  bool operator==(const Time &other) const;
  bool operator==(const ConstTime &other) const;
  bool operator!=(const Time &other) const { return !(*this == other); }
  bool operator!=(const ConstTime &other) const { return !(*this == other); }

  const mg_time *ptr() const { return ptr_; }

 private:
  mg_time *ptr_;
};

class ConstTime final {
 public:
  explicit ConstTime(const mg_time *const_ptr) : const_ptr_(const_ptr) {}

  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_time_nanoseconds(const_ptr_); }
  /// Returns time zone offset in seconds from UTC.
  int64_t tz_offset_seconds() const {
    return mg_time_tz_offset_seconds(const_ptr_);
  }

  bool operator==(const ConstTime &other) const;
  bool operator==(const Time &other) const;
  bool operator!=(const ConstTime &other) const { return !(*this == other); }
  bool operator!=(const Time &other) const { return !(*this == other); }

  const mg_time *ptr() const { return const_ptr_; };

 private:
  const mg_time *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// LocalTime:

/// \brief Wrapper class for \ref mg_local_time
class LocalTime final {
 private:
  friend class Value;

 public:
  explicit LocalTime(mg_local_time *ptr) : ptr_(ptr) {}

  explicit LocalTime(const mg_local_time *const_ptr)
      : LocalTime(mg_local_time_copy(const_ptr)) {}

  LocalTime(const LocalTime &other);
  LocalTime(LocalTime &&other);
  LocalTime &operator=(const LocalTime &other);
  LocalTime &operator=(LocalTime &&other);
  ~LocalTime();

  explicit LocalTime(const ConstLocalTime &local_time);

  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_local_time_nanoseconds(ptr_); }

  ConstLocalTime AsConstLocalTime() const;

  bool operator==(const LocalTime &other) const;
  bool operator==(const ConstLocalTime &other) const;
  bool operator!=(const LocalTime &other) const { return !(*this == other); }
  bool operator!=(const ConstLocalTime &other) const {
    return !(*this == other);
  }

  const mg_local_time *ptr() const { return ptr_; }

 private:
  mg_local_time *ptr_;
};

class ConstLocalTime final {
 public:
  explicit ConstLocalTime(const mg_local_time *const_ptr)
      : const_ptr_(const_ptr) {}

  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_local_time_nanoseconds(const_ptr_); }

  bool operator==(const ConstLocalTime &other) const;
  bool operator==(const LocalTime &other) const;
  bool operator!=(const ConstLocalTime &other) const {
    return !(*this == other);
  }
  bool operator!=(const LocalTime &other) const { return !(*this == other); }

  const mg_local_time *ptr() const { return const_ptr_; };

 private:
  const mg_local_time *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// DateTime:

/// \brief Wrapper class for \ref mg_date_time
class DateTime final {
 private:
  friend class Value;

 public:
  explicit DateTime(mg_date_time *ptr) : ptr_(ptr) {}

  explicit DateTime(const mg_date_time *const_ptr)
      : DateTime(mg_date_time_copy(const_ptr)) {}

  DateTime(const DateTime &other);
  DateTime(DateTime &&other);
  DateTime &operator=(const DateTime &other);
  DateTime &operator=(DateTime &&other);
  ~DateTime();

  explicit DateTime(const ConstDateTime &date_time);

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_date_time_seconds(ptr_); }
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_date_time_nanoseconds(ptr_); }
  /// Returns time zone offset in minutes from UTC.
  int64_t tz_offset_minutes() const {
    return mg_date_time_tz_offset_minutes(ptr_);
  }

  ConstDateTime AsConstDateTime() const;

  bool operator==(const DateTime &other) const;
  bool operator==(const ConstDateTime &other) const;
  bool operator!=(const DateTime &other) const { return !(*this == other); }
  bool operator!=(const ConstDateTime &other) const {
    return !(*this == other);
  }

  const mg_date_time *ptr() const { return ptr_; }

 private:
  mg_date_time *ptr_;
};

class ConstDateTime final {
 public:
  explicit ConstDateTime(const mg_date_time *const_ptr)
      : const_ptr_(const_ptr) {}

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_date_time_seconds(const_ptr_); }
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_date_time_nanoseconds(const_ptr_); }
  /// Returns time zone offset in minutes from UTC.
  int64_t tz_offset_minutes() const {
    return mg_date_time_tz_offset_minutes(const_ptr_);
  }

  bool operator==(const ConstDateTime &other) const;
  bool operator==(const DateTime &other) const;
  bool operator!=(const ConstDateTime &other) const {
    return !(*this == other);
  }
  bool operator!=(const DateTime &other) const { return !(*this == other); }

  const mg_date_time *ptr() const { return const_ptr_; };

 private:
  const mg_date_time *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// DateTimeZoneId:

/// \brief Wrapper class for \ref mg_date_time_zone_id
class DateTimeZoneId final {
 private:
  friend class Value;

 public:
  explicit DateTimeZoneId(mg_date_time_zone_id *ptr) : ptr_(ptr) {}

  explicit DateTimeZoneId(const mg_date_time_zone_id *const_ptr)
      : DateTimeZoneId(mg_date_time_zone_id_copy(const_ptr)) {}

  DateTimeZoneId(const DateTimeZoneId &other);
  DateTimeZoneId(DateTimeZoneId &&other);
  DateTimeZoneId &operator=(const DateTimeZoneId &other);
  DateTimeZoneId &operator=(DateTimeZoneId &&other);
  ~DateTimeZoneId();

  explicit DateTimeZoneId(const ConstDateTimeZoneId &date_time_zone_id);

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_date_time_zone_id_seconds(ptr_); };
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_date_time_zone_id_nanoseconds(ptr_); }
  /// Returns time zone represented by the identifier.
  std::string_view timezoneName() const {
    const mg_string *name = mg_date_time_zone_id_timezone_name(ptr_);
    return std::string_view{mg_string_data(name), mg_string_size(name)};
  }

  ConstDateTimeZoneId AsConstDateTimeZoneId() const;

  bool operator==(const DateTimeZoneId &other) const;
  bool operator==(const ConstDateTimeZoneId &other) const;
  bool operator!=(const DateTimeZoneId &other) const {
    return !(*this == other);
  }
  bool operator!=(const ConstDateTimeZoneId &other) const {
    return !(*this == other);
  }

  const mg_date_time_zone_id *ptr() const { return ptr_; }

 private:
  mg_date_time_zone_id *ptr_;
};

class ConstDateTimeZoneId final {
 public:
  explicit ConstDateTimeZoneId(const mg_date_time_zone_id *const_ptr)
      : const_ptr_(const_ptr) {}

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_date_time_zone_id_seconds(const_ptr_); };
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const {
    return mg_date_time_zone_id_nanoseconds(const_ptr_);
  }
  /// Returns time zone represented by the identifier.
  std::string_view timezoneName() const {
    const mg_string *name = mg_date_time_zone_id_timezone_name(const_ptr_);
    return std::string_view{mg_string_data(name), mg_string_size(name)};
  }

  bool operator==(const ConstDateTimeZoneId &other) const;
  bool operator==(const DateTimeZoneId &other) const;
  bool operator!=(const ConstDateTimeZoneId &other) const {
    return !(*this == other);
  }
  bool operator!=(const DateTimeZoneId &other) const {
    return !(*this == other);
  }

  const mg_date_time_zone_id *ptr() const { return const_ptr_; };

 private:
  const mg_date_time_zone_id *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// LocalDateTime:

/// \brief Wrapper class for \ref mg_local_date_time
class LocalDateTime final {
 private:
  friend class Value;

 public:
  explicit LocalDateTime(mg_local_date_time *ptr) : ptr_(ptr) {}

  explicit LocalDateTime(const mg_local_date_time *const_ptr)
      : LocalDateTime(mg_local_date_time_copy(const_ptr)) {}

  LocalDateTime(const LocalDateTime &other);
  LocalDateTime(LocalDateTime &&other);
  LocalDateTime &operator=(const LocalDateTime &other);
  LocalDateTime &operator=(LocalDateTime &&other);
  ~LocalDateTime();

  explicit LocalDateTime(const ConstLocalDateTime &local_date_time);

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_local_date_time_seconds(ptr_); }
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const { return mg_local_date_time_nanoseconds(ptr_); }

  ConstLocalDateTime AsConstLocalDateTime() const;

  bool operator==(const LocalDateTime &other) const;
  bool operator==(const ConstLocalDateTime &other) const;
  bool operator!=(const LocalDateTime &other) const {
    return !(*this == other);
  }
  bool operator!=(const ConstLocalDateTime &other) const {
    return !(*this == other);
  }

  const mg_local_date_time *ptr() const { return ptr_; }

 private:
  mg_local_date_time *ptr_;
};

class ConstLocalDateTime final {
 public:
  explicit ConstLocalDateTime(const mg_local_date_time *const_ptr)
      : const_ptr_(const_ptr) {}

  /// Returns seconds since Unix epoch.
  int64_t seconds() const { return mg_local_date_time_seconds(const_ptr_); }
  /// Returns nanoseconds since midnight.
  int64_t nanoseconds() const {
    return mg_local_date_time_nanoseconds(const_ptr_);
  }

  bool operator==(const ConstLocalDateTime &other) const;
  bool operator==(const LocalDateTime &other) const;
  bool operator!=(const ConstLocalDateTime &other) const {
    return !(*this == other);
  }
  bool operator!=(const LocalDateTime &other) const {
    return !(*this == other);
  }

  const mg_local_date_time *ptr() const { return const_ptr_; };

 private:
  const mg_local_date_time *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Duration:

/// \brief Wrapper class for \ref mg_duration
class Duration final {
 private:
  friend class Value;

 public:
  explicit Duration(mg_duration *ptr) : ptr_(ptr) {}

  explicit Duration(const mg_duration *const_ptr)
      : Duration(mg_duration_copy(const_ptr)) {}

  Duration(const Duration &other);
  Duration(Duration &&other);
  Duration &operator=(const Duration &other);
  Duration &operator=(Duration &&other);
  ~Duration();

  explicit Duration(const ConstDuration &duration);

  /// Returns the months part of the temporal amount.
  int64_t months() const { return mg_duration_months(ptr_); }
  /// Returns the days part of the temporal amount.
  int64_t days() const { return mg_duration_days(ptr_); }
  /// Returns the seconds part of the temporal amount.
  int64_t seconds() const { return mg_duration_seconds(ptr_); }
  /// Returns the nanoseconds part of the temporal amount.
  int64_t nanoseconds() const { return mg_duration_nanoseconds(ptr_); }

  ConstDuration AsConstDuration() const;

  bool operator==(const Duration &other) const;
  bool operator==(const ConstDuration &other) const;
  bool operator!=(const Duration &other) const { return !(*this == other); }
  bool operator!=(const ConstDuration &other) const {
    return !(*this == other);
  }

  const mg_duration *ptr() const { return ptr_; }

 private:
  mg_duration *ptr_;
};

class ConstDuration final {
 public:
  explicit ConstDuration(const mg_duration *const_ptr)
      : const_ptr_(const_ptr) {}

  /// Returns the months part of the temporal amount.
  int64_t months() const { return mg_duration_months(const_ptr_); }
  /// Returns the days part of the temporal amount.
  int64_t days() const { return mg_duration_days(const_ptr_); }
  /// Returns the seconds part of the temporal amount.
  int64_t seconds() const { return mg_duration_seconds(const_ptr_); }
  /// Returns the nanoseconds part of the temporal amount.
  int64_t nanoseconds() const { return mg_duration_nanoseconds(const_ptr_); }

  bool operator==(const ConstDuration &other) const;
  bool operator==(const Duration &other) const;
  bool operator!=(const ConstDuration &other) const {
    return !(*this == other);
  }
  bool operator!=(const Duration &other) const { return !(*this == other); }

  const mg_duration *ptr() const { return const_ptr_; };

 private:
  const mg_duration *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Point2d:

/// \brief Wrapper class for \ref mg_point_2d
class Point2d final {
 private:
  friend class Value;

 public:
  explicit Point2d(mg_point_2d *ptr) : ptr_(ptr) {}

  explicit Point2d(const mg_point_2d *const_ptr)
      : Point2d(mg_point_2d_copy(const_ptr)) {}

  Point2d(const Point2d &other);
  Point2d(Point2d &&other);
  Point2d &operator=(const Point2d &other);
  Point2d &operator=(Point2d &&other);
  ~Point2d();

  explicit Point2d(const ConstPoint2d &point_2d);

  /// Returns SRID of the 2D point.
  int64_t srid() const { return mg_point_2d_srid(ptr_); }
  /// Returns the x coordinate of the 2D point.
  double x() const { return mg_point_2d_x(ptr_); }
  /// Returns the y coordinate of the 2D point.
  double y() const { return mg_point_2d_y(ptr_); }

  ConstPoint2d AsConstPoint2d() const;

  bool operator==(const Point2d &other) const;
  bool operator==(const ConstPoint2d &other) const;
  bool operator!=(const Point2d &other) const { return !(*this == other); }
  bool operator!=(const ConstPoint2d &other) const { return !(*this == other); }

  const mg_point_2d *ptr() const { return ptr_; }

 private:
  mg_point_2d *ptr_;
};

class ConstPoint2d final {
 public:
  explicit ConstPoint2d(const mg_point_2d *const_ptr) : const_ptr_(const_ptr) {}

  /// Returns SRID of the 2D point.
  int64_t srid() const { return mg_point_2d_srid(const_ptr_); }
  /// Returns the x coordinate of the 2D point.
  double x() const { return mg_point_2d_x(const_ptr_); }
  /// Returns the y coordinate of the 2D point.
  double y() const { return mg_point_2d_y(const_ptr_); }

  bool operator==(const ConstPoint2d &other) const;
  bool operator==(const Point2d &other) const;
  bool operator!=(const ConstPoint2d &other) const { return !(*this == other); }
  bool operator!=(const Point2d &other) const { return !(*this == other); }

  const mg_point_2d *ptr() const { return const_ptr_; };

 private:
  const mg_point_2d *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Point3d:

/// \brief Wrapper class for \ref mg_point_3d
class Point3d final {
 private:
  friend class Value;

 public:
  explicit Point3d(mg_point_3d *ptr) : ptr_(ptr) {}

  explicit Point3d(const mg_point_3d *const_ptr)
      : Point3d(mg_point_3d_copy(const_ptr)) {}

  Point3d(const Point3d &other);
  Point3d(Point3d &&other);
  Point3d &operator=(const Point3d &other);
  Point3d &operator=(Point3d &&other);
  ~Point3d();

  explicit Point3d(const ConstPoint3d &point_3d);

  /// Returns SRID of the 3D point.
  int64_t srid() const { return mg_point_3d_srid(ptr_); }
  /// Returns the x coordinate of the 3D point.
  double x() const { return mg_point_3d_x(ptr_); }
  /// Returns the y coordinate of the 3D point.
  double y() const { return mg_point_3d_y(ptr_); }
  /// Returns the z coordinate of the 3D point.
  double z() const { return mg_point_3d_z(ptr_); }

  ConstPoint3d AsConstPoint3d() const;

  bool operator==(const Point3d &other) const;
  bool operator==(const ConstPoint3d &other) const;
  bool operator!=(const Point3d &other) const { return !(*this == other); }
  bool operator!=(const ConstPoint3d &other) const { return !(*this == other); }

  const mg_point_3d *ptr() const { return ptr_; }

 private:
  mg_point_3d *ptr_;
};

class ConstPoint3d final {
 public:
  explicit ConstPoint3d(const mg_point_3d *const_ptr) : const_ptr_(const_ptr) {}

  /// Returns SRID of the 3D point.
  int64_t srid() const { return mg_point_3d_srid(const_ptr_); }
  /// Returns the x coordinate of the 3D point.
  double x() const { return mg_point_3d_x(const_ptr_); }
  /// Returns the y coordinate of the 3D point.
  double y() const { return mg_point_3d_y(const_ptr_); }
  /// Returns the z coordinate of the 3D point.
  double z() const { return mg_point_3d_z(const_ptr_); }

  bool operator==(const ConstPoint3d &other) const;
  bool operator==(const Point3d &other) const;
  bool operator!=(const ConstPoint3d &other) const { return !(*this == other); }
  bool operator!=(const Point3d &other) const { return !(*this == other); }

  const mg_point_3d *ptr() const { return const_ptr_; };

 private:
  const mg_point_3d *const_ptr_;
};

////////////////////////////////////////////////////////////////////////////////
// Value:

/// Wrapper class for \ref mg_value
class Value final {
 private:
  friend class List;
  friend class Map;

 public:
  /// \brief Types that can be stored in a `Value`.
  enum class Type : uint8_t {
    Null,
    Bool,
    Int,
    Double,
    String,
    List,
    Map,
    Node,
    Relationship,
    UnboundRelationship,
    Path,
    Date,
    Time,
    LocalTime,
    DateTime,
    DateTimeZoneId,
    LocalDateTime,
    Duration,
    Point2d,
    Point3d
  };

  /// \brief Constructs an object that becomes the owner of the given `value`.
  /// `value` is destroyed when a `Value` object is destroyed.
  explicit Value(mg_value *ptr) : ptr_(ptr) {}

  /// \brief Creates a Value from a copy of the given \ref mg_value.
  explicit Value(const mg_value *const_ptr) : Value(mg_value_copy(const_ptr)) {}

  Value(const Value &other);
  Value(Value &&other);
  Value &operator=(const Value &other) = delete;
  Value &operator=(Value &&other) = delete;
  ~Value();

  explicit Value(const ConstValue &value);

  /// \brief Creates Null value.
  Value() : Value(mg_value_make_null()) {}

  // Constructors for primitive types:
  explicit Value(bool value) : Value(mg_value_make_bool(value)) {}
  explicit Value(int value) : Value(mg_value_make_integer(value)) {}
  explicit Value(int64_t value) : Value(mg_value_make_integer(value)) {}
  explicit Value(double value) : Value(mg_value_make_float(value)) {}

  // Constructors for string:
  explicit Value(const std::string_view value);
  explicit Value(const char *value);

  /// \brief Constructs a list value and takes the ownership of the `list`.
  /// \note
  /// Behaviour of accessing the `list` after performing this operation is
  /// considered undefined.
  explicit Value(List &&list);

  /// \brief Constructs a map value and takes the ownership of the `map`.
  /// \note
  /// Behaviour of accessing the `map` after performing this operation is
  /// considered undefined.
  explicit Value(Map &&map);

  /// \brief Constructs a vertex value and takes the ownership of the given
  /// `vertex`. \note Behaviour of accessing the `vertex` after performing this
  /// operation is considered undefined.
  explicit Value(Node &&vertex);

  /// \brief Constructs an edge value and takes the ownership of the given
  /// `edge`. \note Behaviour of accessing the `edge` after performing this
  /// operation is considered undefined.
  explicit Value(Relationship &&edge);

  /// \brief Constructs an unbounded edge value and takes the ownership of the
  /// given `edge`. \note Behaviour of accessing the `edge` after performing
  /// this operation is considered undefined.
  explicit Value(UnboundRelationship &&edge);

  /// \brief Constructs a path value and takes the ownership of the given
  /// `path`. \note Behaviour of accessing the `path` after performing this
  /// operation is considered undefined.
  explicit Value(Path &&path);

  /// \brief Constructs a date value and takes the ownership of the given
  /// `date`. \note Behaviour of accessing the `date` after performing this
  /// operation is considered undefined.
  explicit Value(Date &&date);

  /// \brief Constructs a time value and takes the ownership of the given
  /// `time`. \note Behaviour of accessing the `time` after performing this
  /// operation is considered undefined.
  explicit Value(Time &&time);

  /// \brief Constructs a LocalTime value and takes the ownership of the given
  /// `localTime`. \note Behaviour of accessing the `localTime` after performing
  /// this operation is considered undefined.
  explicit Value(LocalTime &&localTime);

  /// \brief Constructs a DateTime value and takes the ownership of the given
  /// `dateTime`. \note Behaviour of accessing the `dateTime` after performing
  /// this operation is considered undefined.
  explicit Value(DateTime &&dateTime);

  /// \brief Constructs a DateTimeZoneId value and takes the ownership of the
  /// given `dateTimeZoneId`. \note Behaviour of accessing the `dateTimeZoneId`
  /// after performing this operation is considered undefined.
  explicit Value(DateTimeZoneId &&dateTimeZoneId);

  /// \brief Constructs a LocalDateTime value and takes the ownership of the
  /// given `localDateTime`. \note Behaviour of accessing the `localDateTime`
  /// after performing this operation is considered undefined.
  explicit Value(LocalDateTime &&localDateTime);

  /// \brief Constructs a Duration value and takes the ownership of the given
  /// `duration`. \note Behaviour of accessing the `duration` after performing
  /// this operation is considered undefined.
  explicit Value(Duration &&duration);

  /// \brief Constructs a Point2d value and takes the ownership of the given
  /// `point2d`. \note Behaviour of accessing the `point2d` after performing
  /// this operation is considered undefined.
  explicit Value(Point2d &&point2d);

  /// \brief Constructs a Point3d value and takes the ownership of the given
  /// `point3d`. \note Behaviour of accessing the `point3d` after performing
  /// this operation is considered undefined.
  explicit Value(Point3d &&point3d);

  /// \pre value type is Type::Bool
  bool ValueBool() const;
  /// \pre value type is Type::Int
  int64_t ValueInt() const;
  /// \pre value type is Type::Double
  double ValueDouble() const;
  /// \pre value type is Type::String
  std::string_view ValueString() const;
  /// \pre value type is Type::List
  const ConstList ValueList() const;
  /// \pre value type is Type::Map
  const ConstMap ValueMap() const;
  /// \pre value type is Type::Node
  const ConstNode ValueNode() const;
  /// \pre value type is Type::Relationship
  const ConstRelationship ValueRelationship() const;
  /// \pre value type is Type::UnboundRelationship
  const ConstUnboundRelationship ValueUnboundRelationship() const;
  /// \pre value type is Type::Path
  const ConstPath ValuePath() const;
  /// \pre value type is Type::Date
  const ConstDate ValueDate() const;
  /// \pre value type is Type::Time
  const ConstTime ValueTime() const;
  /// \pre value type is Type::LocalTime
  const ConstLocalTime ValueLocalTime() const;
  /// \pre value type is Type::DateTime
  const ConstDateTime ValueDateTime() const;
  /// \pre value type is Type::DateTimeZoneId
  const ConstDateTimeZoneId ValueDateTimeZoneId() const;
  /// \pre value type is Type::LocalDateTime
  const ConstLocalDateTime ValueLocalDateTime() const;
  /// \pre value type is Type::Duration
  const ConstDuration ValueDuration() const;
  /// \pre value type is Type::Point2d
  const ConstPoint2d ValuePoint2d() const;
  /// \pre value type is Type::Point3d
  const ConstPoint3d ValuePoint3d() const;

  /// \exception std::runtime_error the value type is unknown
  Type type() const;

  ConstValue AsConstValue() const;

  /// \exception std::runtime_error the value type is unknown
  bool operator==(const Value &other) const;
  /// \exception std::runtime_error the value type is unknown
  bool operator==(const ConstValue &other) const;
  /// \exception std::runtime_error the value type is unknown
  bool operator!=(const Value &other) const { return !(*this == other); }
  /// \exception std::runtime_error the value type is unknown
  bool operator!=(const ConstValue &other) const { return !(*this == other); }

  const mg_value *ptr() const { return ptr_; }

 private:
  mg_value *ptr_;
};

class ConstValue final {
 public:
  explicit ConstValue(const mg_value *const_ptr) : const_ptr_(const_ptr) {}

  /// \pre value type is Type::Bool
  bool ValueBool() const;
  /// \pre value type is Type::Int
  int64_t ValueInt() const;
  /// \pre value type is Type::Double
  double ValueDouble() const;
  /// \pre value type is Type::String
  std::string_view ValueString() const;
  /// \pre value type is Type::List
  const ConstList ValueList() const;
  /// \pre value type is Type::Map
  const ConstMap ValueMap() const;
  /// \pre value type is Type::Node
  const ConstNode ValueNode() const;
  /// \pre value type is Type::Relationship
  const ConstRelationship ValueRelationship() const;
  /// \pre value type is Type::UnboundRelationship
  const ConstUnboundRelationship ValueUnboundRelationship() const;
  /// \pre value type is Type::Path
  const ConstPath ValuePath() const;
  /// \pre value type is Type::Date
  const ConstDate ValueDate() const;
  /// \pre value type is Type::Time
  const ConstTime ValueTime() const;
  /// \pre value type is Type::LocalTime
  const ConstLocalTime ValueLocalTime() const;
  /// \pre value type is Type::DateTime
  const ConstDateTime ValueDateTime() const;
  /// \pre value type is Type::DateTimeZoneId
  const ConstDateTimeZoneId ValueDateTimeZoneId() const;
  /// \pre value type is Type::LocalDateTime
  const ConstLocalDateTime ValueLocalDateTime() const;
  /// \pre value type is Type::Duration
  const ConstDuration ValueDuration() const;
  /// \pre value type is Type::Point2d
  const ConstPoint2d ValuePoint2d() const;
  /// \pre value type is Type::Point3d
  const ConstPoint3d ValuePoint3d() const;

  /// \exception std::runtime_error the value type is unknown
  Value::Type type() const;

  /// \exception std::runtime_error the value type is unknown
  bool operator==(const ConstValue &other) const;
  /// \exception std::runtime_error the value type is unknown
  bool operator==(const Value &other) const;
  /// \exception std::runtime_error the value type is unknown
  bool operator!=(const ConstValue &other) const { return !(*this == other); }
  /// \exception std::runtime_error the value type is unknown
  bool operator!=(const Value &other) const { return !(*this == other); }

  const mg_value *ptr() const { return const_ptr_; }

 private:
  const mg_value *const_ptr_;
};

#undef CREATE_ITERATOR

namespace detail {
inline std::string_view ConvertString(const mg_string *str) {
  return std::string_view(mg_string_data(str), mg_string_size(str));
}

inline Value::Type ConvertType(mg_value_type type) {
  switch (type) {
    case MG_VALUE_TYPE_NULL:
      return Value::Type::Null;
    case MG_VALUE_TYPE_BOOL:
      return Value::Type::Bool;
    case MG_VALUE_TYPE_INTEGER:
      return Value::Type::Int;
    case MG_VALUE_TYPE_FLOAT:
      return Value::Type::Double;
    case MG_VALUE_TYPE_STRING:
      return Value::Type::String;
    case MG_VALUE_TYPE_LIST:
      return Value::Type::List;
    case MG_VALUE_TYPE_MAP:
      return Value::Type::Map;
    case MG_VALUE_TYPE_NODE:
      return Value::Type::Node;
    case MG_VALUE_TYPE_RELATIONSHIP:
      return Value::Type::Relationship;
    case MG_VALUE_TYPE_UNBOUND_RELATIONSHIP:
      return Value::Type::UnboundRelationship;
    case MG_VALUE_TYPE_PATH:
      return Value::Type::Path;
    case MG_VALUE_TYPE_DATE:
      return Value::Type::Date;
    case MG_VALUE_TYPE_TIME:
      return Value::Type::Time;
    case MG_VALUE_TYPE_LOCAL_TIME:
      return Value::Type::LocalTime;
    case MG_VALUE_TYPE_DATE_TIME:
      return Value::Type::DateTime;
    case MG_VALUE_TYPE_DATE_TIME_ZONE_ID:
      return Value::Type::DateTimeZoneId;
    case MG_VALUE_TYPE_LOCAL_DATE_TIME:
      return Value::Type::LocalDateTime;
    case MG_VALUE_TYPE_DURATION:
      return Value::Type::Duration;
    case MG_VALUE_TYPE_POINT_2D:
      return Value::Type::Point2d;
    case MG_VALUE_TYPE_POINT_3D:
      return Value::Type::Point3d;
    case MG_VALUE_TYPE_UNKNOWN:
      throw std::runtime_error("Unknown value type!");
  }
  std::abort();
}

inline bool AreValuesEqual(const mg_value *value1, const mg_value *value2);

inline bool AreStringsEqual(const mg_string *s1, const mg_string *s2) {
  if (s1 == s2) return true;
  if (!s1 || !s2) return false;
  return mg_string_size(s1) == mg_string_size(s2) &&
         memcmp(mg_string_data(s1), mg_string_data(s2), mg_string_size(s1)) ==
             0;
}

inline bool AreListsEqual(const mg_list *list1, const mg_list *list2) {
  if (list1 == list2) {
    return true;
  }
  if (mg_list_size(list1) != mg_list_size(list2)) {
    return false;
  }
  const size_t len = mg_list_size(list1);
  for (size_t i = 0; i < len; ++i) {
    if (!detail::AreValuesEqual(mg_list_at(list1, i), mg_list_at(list2, i))) {
      return false;
    }
  }
  return true;
}

inline bool AreMapsEqual(const mg_map *map1, const mg_map *map2) {
  if (map1 == map2) {
    return true;
  }
  if (mg_map_size(map1) != mg_map_size(map2)) {
    return false;
  }
  const size_t len = mg_map_size(map1);
  for (size_t i = 0; i < len; ++i) {
    const mg_string *key = mg_map_key_at(map1, i);
    const mg_value *value1 = mg_map_value_at(map1, i);
    const mg_value *value2 =
        mg_map_at2(map2, mg_string_size(key), mg_string_data(key));
    if (value2 == nullptr) {
      return false;
    }
    if (!detail::AreValuesEqual(value1, value2)) {
      return false;
    }
  }
  return true;
}

inline bool AreNodesEqual(const mg_node *node1, const mg_node *node2) {
  if (node1 == node2) {
    return true;
  }
  if (mg_node_id(node1) != mg_node_id(node2)) {
    return false;
  }
  if (mg_node_label_count(node1) != mg_node_label_count(node2)) {
    return false;
  }
  std::set<std::string_view> labels1;
  std::set<std::string_view> labels2;
  const size_t label_count = mg_node_label_count(node1);
  for (size_t i = 0; i < label_count; ++i) {
    labels1.insert(detail::ConvertString(mg_node_label_at(node1, i)));
    labels2.insert(detail::ConvertString(mg_node_label_at(node2, i)));
  }
  if (labels1 != labels2) {
    return false;
  }
  return detail::AreMapsEqual(mg_node_properties(node1),
                              mg_node_properties(node2));
}

inline bool AreRelationshipsEqual(const mg_relationship *rel1,
                                  const mg_relationship *rel2) {
  if (rel1 == rel2) {
    return true;
  }
  if (mg_relationship_id(rel1) != mg_relationship_id(rel2)) {
    return false;
  }
  if (mg_relationship_start_id(rel1) != mg_relationship_start_id(rel2)) {
    return false;
  }
  if (mg_relationship_end_id(rel1) != mg_relationship_end_id(rel2)) {
    return false;
  }
  if (detail::ConvertString(mg_relationship_type(rel1)) !=
      detail::ConvertString(mg_relationship_type(rel2))) {
    return false;
  }
  return detail::AreMapsEqual(mg_relationship_properties(rel1),
                              mg_relationship_properties(rel2));
}

inline bool AreUnboundRelationshipsEqual(const mg_unbound_relationship *rel1,
                                         const mg_unbound_relationship *rel2) {
  if (rel1 == rel2) {
    return true;
  }
  if (mg_unbound_relationship_id(rel1) != mg_unbound_relationship_id(rel2)) {
    return false;
  }
  if (detail::ConvertString(mg_unbound_relationship_type(rel1)) !=
      detail::ConvertString(mg_unbound_relationship_type(rel2))) {
    return false;
  }
  return detail::AreMapsEqual(mg_unbound_relationship_properties(rel1),
                              mg_unbound_relationship_properties(rel2));
}

inline bool ArePathsEqual(const mg_path *path1, const mg_path *path2) {
  if (path1 == path2) {
    return true;
  }
  if (mg_path_length(path1) != mg_path_length(path2)) {
    return false;
  }
  const size_t len = mg_path_length(path1);
  for (size_t i = 0; i < len; ++i) {
    if (!detail::AreNodesEqual(mg_path_node_at(path1, i),
                               mg_path_node_at(path2, i))) {
      return false;
    }
    if (!detail::AreUnboundRelationshipsEqual(
            mg_path_relationship_at(path1, i),
            mg_path_relationship_at(path2, i))) {
      return false;
    }
    if (mg_path_relationship_reversed_at(path1, i) !=
        mg_path_relationship_reversed_at(path2, i)) {
      return false;
    }
  }
  return detail::AreNodesEqual(mg_path_node_at(path1, len),
                               mg_path_node_at(path2, len));
}

inline bool AreDatesEqual(const mg_date *date1, const mg_date *date2) {
  return mg_date_days(date1) == mg_date_days(date2);
}

inline bool AreTimesEqual(const mg_time *time1, const mg_time *time2) {
  return mg_time_nanoseconds(time1) == mg_time_nanoseconds(time2) &&
         mg_time_tz_offset_seconds(time1) == mg_time_tz_offset_seconds(time2);
}

inline bool AreLocalTimesEqual(const mg_local_time *local_time1,
                               const mg_local_time *local_time2) {
  return mg_local_time_nanoseconds(local_time1) ==
         mg_local_time_nanoseconds(local_time2);
}

inline bool AreDateTimesEqual(const mg_date_time *date_time1,
                              const mg_date_time *date_time2) {
  return mg_date_time_seconds(date_time1) == mg_date_time_seconds(date_time2) &&
         mg_date_time_nanoseconds(date_time1) ==
             mg_date_time_nanoseconds(date_time2) &&
         mg_date_time_tz_offset_minutes(date_time1) ==
             mg_date_time_tz_offset_minutes(date_time2);
}

inline bool AreDateTimeZoneIdsEqual(
    const mg_date_time_zone_id *date_time_zone_id1,
    const mg_date_time_zone_id *date_time_zone_id2) {
  return mg_date_time_zone_id_seconds(date_time_zone_id1) ==
             mg_date_time_zone_id_seconds(date_time_zone_id2) &&
         mg_date_time_zone_id_nanoseconds(date_time_zone_id1) ==
             mg_date_time_zone_id_nanoseconds(date_time_zone_id2) &&
         detail::AreStringsEqual(
             mg_date_time_zone_id_timezone_name(date_time_zone_id1),
             mg_date_time_zone_id_timezone_name(date_time_zone_id2));
}

inline bool AreLocalDateTimesEqual(const mg_local_date_time *local_date_time1,
                                   const mg_local_date_time *local_date_time2) {
  return mg_local_date_time_seconds(local_date_time1) ==
             mg_local_date_time_seconds(local_date_time2) &&
         mg_local_date_time_nanoseconds(local_date_time1) ==
             mg_local_date_time_nanoseconds(local_date_time2);
}

inline bool AreDurationsEqual(const mg_duration *duration1,
                              const mg_duration *duration2) {
  return mg_duration_months(duration1) == mg_duration_months(duration2) &&
         mg_duration_days(duration1) == mg_duration_days(duration2) &&
         mg_duration_seconds(duration1) == mg_duration_seconds(duration2) &&
         mg_duration_nanoseconds(duration1) ==
             mg_duration_nanoseconds(duration2);
}

inline bool ArePoint2dsEqual(const mg_point_2d *point_2d1,
                             const mg_point_2d *point_2d2) {
  return mg_point_2d_srid(point_2d1) == mg_point_2d_srid(point_2d2) &&
         mg_point_2d_x(point_2d1) == mg_point_2d_x(point_2d2) &&
         mg_point_2d_y(point_2d1) == mg_point_2d_y(point_2d2);
}

inline bool ArePoint3dsEqual(const mg_point_3d *point_3d1,
                             const mg_point_3d *point_3d2) {
  return mg_point_3d_srid(point_3d1) == mg_point_3d_srid(point_3d2) &&
         mg_point_3d_x(point_3d1) == mg_point_3d_x(point_3d2) &&
         mg_point_3d_y(point_3d1) == mg_point_3d_y(point_3d2) &&
         mg_point_3d_z(point_3d1) == mg_point_3d_z(point_3d2);
}

inline bool AreValuesEqual(const mg_value *value1, const mg_value *value2) {
  if (value1 == value2) {
    return true;
  }
  if (mg_value_get_type(value1) != mg_value_get_type(value2)) {
    return false;
  }
  switch (mg_value_get_type(value1)) {
    case MG_VALUE_TYPE_NULL:
      return true;
    case MG_VALUE_TYPE_BOOL:
      return mg_value_bool(value1) == mg_value_bool(value2);
    case MG_VALUE_TYPE_INTEGER:
      return mg_value_integer(value1) == mg_value_integer(value2);
    case MG_VALUE_TYPE_FLOAT:
      return mg_value_float(value1) == mg_value_float(value2);
    case MG_VALUE_TYPE_STRING:
      return detail::ConvertString(mg_value_string(value1)) ==
             detail::ConvertString(mg_value_string(value2));
    case MG_VALUE_TYPE_LIST:
      return detail::AreListsEqual(mg_value_list(value1),
                                   mg_value_list(value2));
    case MG_VALUE_TYPE_MAP:
      return detail::AreMapsEqual(mg_value_map(value1), mg_value_map(value2));
    case MG_VALUE_TYPE_NODE:
      return detail::AreNodesEqual(mg_value_node(value1),
                                   mg_value_node(value2));
    case MG_VALUE_TYPE_RELATIONSHIP:
      return detail::AreRelationshipsEqual(mg_value_relationship(value1),
                                           mg_value_relationship(value2));
    case MG_VALUE_TYPE_UNBOUND_RELATIONSHIP:
      return detail::AreUnboundRelationshipsEqual(
          mg_value_unbound_relationship(value1),
          mg_value_unbound_relationship(value2));
    case MG_VALUE_TYPE_PATH:
      return detail::ArePathsEqual(mg_value_path(value1),
                                   mg_value_path(value2));
    case MG_VALUE_TYPE_DATE:
      return detail::AreDatesEqual(mg_value_date(value1),
                                   mg_value_date(value2));
    case MG_VALUE_TYPE_TIME:
      return detail::AreTimesEqual(mg_value_time(value1),
                                   mg_value_time(value2));
    case MG_VALUE_TYPE_LOCAL_TIME:
      return detail::AreLocalTimesEqual(mg_value_local_time(value1),
                                        mg_value_local_time(value2));
    case MG_VALUE_TYPE_DATE_TIME:
      return detail::AreDateTimesEqual(mg_value_date_time(value1),
                                       mg_value_date_time(value2));
    case MG_VALUE_TYPE_DATE_TIME_ZONE_ID:
      return detail::AreDateTimeZoneIdsEqual(
          mg_value_date_time_zone_id(value1),
          mg_value_date_time_zone_id(value2));
    case MG_VALUE_TYPE_LOCAL_DATE_TIME:
      return detail::AreLocalDateTimesEqual(mg_value_local_date_time(value1),
                                            mg_value_local_date_time(value2));
    case MG_VALUE_TYPE_DURATION:
      return detail::AreDurationsEqual(mg_value_duration(value1),
                                       mg_value_duration(value2));
    case MG_VALUE_TYPE_POINT_2D:
      return detail::ArePoint2dsEqual(mg_value_point_2d(value1),
                                      mg_value_point_2d(value2));
    case MG_VALUE_TYPE_POINT_3D:
      return detail::ArePoint3dsEqual(mg_value_point_3d(value1),
                                      mg_value_point_3d(value2));
    case MG_VALUE_TYPE_UNKNOWN:
      throw std::runtime_error("Comparing values of unknown types!");
  }
  std::abort();
}
}  // namespace detail

////////////////////////////////////////////////////////////////////////////////
// List:

inline ConstValue List::Iterator::operator*() const {
  return (*iterable_)[index_];
}

inline List::List(const List &other) : ptr_(mg_list_copy(other.ptr_)) {}

inline List::List(List &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline List::~List() {
  if (ptr_ != nullptr) {
    mg_list_destroy(ptr_);
  }
}

inline List::List(const ConstList &list) : ptr_(mg_list_copy(list.ptr())) {}

inline List::List(const std::vector<mg::Value> &values) : List(values.size()) {
  for (const auto &value : values) {
    Append(value);
  }
}

inline List::List(std::vector<mg::Value> &&values) : List(values.size()) {
  for (auto &value : values) {
    Append(std::move(value));
  }
}

inline List::List(std::initializer_list<Value> values) : List(values.size()) {
  for (const auto &value : values) {
    Append(value);
  }
}

inline const ConstValue List::operator[](size_t index) const {
  return ConstValue(mg_list_at(ptr_, index));
}

inline bool List::Append(const Value &value) {
  return mg_list_append(ptr_, mg_value_copy(value.ptr())) == 0;
}

inline bool List::Append(const ConstValue &value) {
  return mg_list_append(ptr_, mg_value_copy(value.ptr())) == 0;
}

inline bool List::Append(Value &&value) {
  bool result = mg_list_append(ptr_, value.ptr_) == 0;
  value.ptr_ = nullptr;
  return result;
}

inline const ConstList List::AsConstList() const { return ConstList(ptr_); }

inline bool List::operator==(const List &other) const {
  return detail::AreListsEqual(ptr_, other.ptr_);
}

inline bool List::operator==(const ConstList &other) const {
  return detail::AreListsEqual(ptr_, other.ptr());
}

inline ConstValue ConstList::Iterator::operator*() const {
  return (*iterable_)[index_];
}

inline const ConstValue ConstList::operator[](size_t index) const {
  return ConstValue(mg_list_at(const_ptr_, index));
}

inline bool ConstList::operator==(const ConstList &other) const {
  return detail::AreListsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstList::operator==(const List &other) const {
  return detail::AreListsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Map:

inline std::pair<std::string_view, ConstValue> Map::Iterator::operator*()
    const {
  return std::make_pair(
      detail::ConvertString(mg_map_key_at(iterable_->ptr(), index_)),
      ConstValue(mg_map_value_at(iterable_->ptr(), index_)));
}

inline Map::Map(const Map &other) : Map(mg_map_copy(other.ptr_)) {}

inline Map::Map(Map &&other) : Map(other.ptr_) { other.ptr_ = nullptr; }

inline Map::Map(const ConstMap &map) : ptr_(mg_map_copy(map.ptr())) {}

inline Map::~Map() {
  if (ptr_ != nullptr) {
    mg_map_destroy(ptr_);
  }
}

inline Map::Map(std::initializer_list<std::pair<std::string, Value>> list)
    : Map(list.size()) {
  for (const auto &[key, value] : list) {
    Insert(key, value.AsConstValue());
  }
}

inline ConstValue Map::operator[](const std::string_view key) const {
  return ConstValue(mg_map_at2(ptr_, key.size(), key.data()));
}

inline Map::Iterator Map::find(const std::string_view key) const {
  for (size_t i = 0; i < size(); ++i) {
    if (key == detail::ConvertString(mg_map_key_at(ptr_, i))) {
      return Iterator(this, i);
    }
  }
  return end();
}

inline bool Map::Insert(const std::string_view key, const Value &value) {
  return mg_map_insert2(ptr_, mg_string_make2(key.size(), key.data()),
                        mg_value_copy(value.ptr())) == 0;
}

inline bool Map::Insert(const std::string_view key, const ConstValue &value) {
  return mg_map_insert2(ptr_, mg_string_make2(key.size(), key.data()),
                        mg_value_copy(value.ptr())) == 0;
}

inline bool Map::Insert(const std::string_view key, Value &&value) {
  bool result = mg_map_insert2(ptr_, mg_string_make2(key.size(), key.data()),
                               value.ptr_) == 0;
  value.ptr_ = nullptr;
  return result;
}

inline bool Map::InsertUnsafe(const std::string_view key, const Value &value) {
  return mg_map_insert_unsafe2(ptr_, mg_string_make2(key.size(), key.data()),
                               mg_value_copy(value.ptr())) == 0;
}

inline bool Map::InsertUnsafe(const std::string_view key,
                              const ConstValue &value) {
  return mg_map_insert_unsafe2(ptr_, mg_string_make2(key.size(), key.data()),
                               mg_value_copy(value.ptr())) == 0;
}

inline bool Map::InsertUnsafe(const std::string_view key, Value &&value) {
  bool result =
      mg_map_insert_unsafe2(ptr_, mg_string_make2(key.size(), key.data()),
                            value.ptr_) == 0;
  value.ptr_ = nullptr;
  return result;
}

inline const ConstMap Map::AsConstMap() const { return ConstMap(ptr_); }

inline bool Map::operator==(const Map &other) const {
  return detail::AreMapsEqual(ptr_, other.ptr_);
}

inline bool Map::operator==(const ConstMap &other) const {
  return detail::AreMapsEqual(ptr_, other.ptr());
}

inline std::pair<std::string_view, ConstValue> ConstMap::Iterator::operator*()
    const {
  return std::make_pair(
      detail::ConvertString(mg_map_key_at(iterable_->ptr(), index_)),
      ConstValue(mg_map_value_at(iterable_->ptr(), index_)));
}

inline ConstValue ConstMap::operator[](const std::string_view key) const {
  return ConstValue(mg_map_at2(const_ptr_, key.size(), key.data()));
}

inline ConstMap::Iterator ConstMap::find(const std::string_view key) const {
  for (size_t i = 0; i < size(); ++i) {
    if (key == detail::ConvertString(mg_map_key_at(const_ptr_, i))) {
      return Iterator(this, i);
    }
  }
  return end();
}

inline bool ConstMap::operator==(const ConstMap &other) const {
  return detail::AreMapsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstMap::operator==(const Map &other) const {
  return detail::AreMapsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Node:

inline std::string_view Node::Labels::Iterator::operator*() const {
  return (*iterable_)[index_];
}

inline std::string_view Node::Labels::operator[](size_t index) const {
  return detail::ConvertString(mg_node_label_at(node_, index));
}

inline Node::Node(const Node &other) : Node(mg_node_copy(other.ptr_)) {}

inline Node::Node(Node &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline Node::~Node() {
  if (ptr_ != nullptr) {
    mg_node_destroy(ptr_);
  }
}

inline Node::Node(const ConstNode &node) : ptr_(mg_node_copy(node.ptr())) {}

inline bool Node::operator==(const Node &other) const {
  return detail::AreNodesEqual(ptr_, other.ptr_);
}

inline bool Node::operator==(const ConstNode &other) const {
  return detail::AreNodesEqual(ptr_, other.ptr());
}

inline ConstNode Node::AsConstNode() const { return ConstNode(ptr_); }

inline bool ConstNode::operator==(const ConstNode &other) const {
  return detail::AreNodesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstNode::operator==(const Node &other) const {
  return detail::AreNodesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Relationship:

inline Relationship::Relationship(const Relationship &other)
    : Relationship(mg_relationship_copy(other.ptr_)) {}

inline Relationship::Relationship(Relationship &&other)
    : Relationship(other.ptr_) {
  other.ptr_ = nullptr;
}

inline Relationship::~Relationship() {
  if (ptr_ != nullptr) {
    mg_relationship_destroy(ptr_);
  }
}

inline Relationship::Relationship(const ConstRelationship &rel)
    : ptr_(mg_relationship_copy(rel.ptr())) {}

inline std::string_view Relationship::type() const {
  return detail::ConvertString(mg_relationship_type(ptr_));
}

inline ConstRelationship Relationship::AsConstRelationship() const {
  return ConstRelationship(ptr_);
}

inline bool Relationship::operator==(const Relationship &other) const {
  return detail::AreRelationshipsEqual(ptr_, other.ptr_);
}

inline bool Relationship::operator==(const ConstRelationship &other) const {
  return detail::AreRelationshipsEqual(ptr_, other.ptr());
}

inline std::string_view ConstRelationship::type() const {
  return detail::ConvertString(mg_relationship_type(const_ptr_));
}

inline bool ConstRelationship::operator==(
    const ConstRelationship &other) const {
  return detail::AreRelationshipsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstRelationship::operator==(const Relationship &other) const {
  return detail::AreRelationshipsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// UnboundRelationship:

inline UnboundRelationship::UnboundRelationship(
    const UnboundRelationship &other)
    : ptr_(mg_unbound_relationship_copy(other.ptr_)) {}

inline UnboundRelationship::UnboundRelationship(UnboundRelationship &&other)
    : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline UnboundRelationship::~UnboundRelationship() {
  if (ptr_ != nullptr) {
    mg_unbound_relationship_destroy(ptr_);
  }
}

inline UnboundRelationship::UnboundRelationship(
    const ConstUnboundRelationship &rel)
    : ptr_(mg_unbound_relationship_copy(rel.ptr())) {}

inline std::string_view UnboundRelationship::type() const {
  return detail::ConvertString(mg_unbound_relationship_type(ptr_));
}

inline ConstUnboundRelationship
UnboundRelationship::AsConstUnboundRelationship() const {
  return ConstUnboundRelationship(ptr_);
}

inline bool UnboundRelationship::operator==(
    const UnboundRelationship &other) const {
  return detail::AreUnboundRelationshipsEqual(ptr_, other.ptr_);
}

inline bool UnboundRelationship::operator==(
    const ConstUnboundRelationship &other) const {
  return detail::AreUnboundRelationshipsEqual(ptr_, other.ptr());
}

inline std::string_view ConstUnboundRelationship::type() const {
  return detail::ConvertString(mg_unbound_relationship_type(const_ptr_));
}

inline bool ConstUnboundRelationship::operator==(
    const ConstUnboundRelationship &other) const {
  return detail::AreUnboundRelationshipsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstUnboundRelationship::operator==(
    const UnboundRelationship &other) const {
  return detail::AreUnboundRelationshipsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Path:

inline Path::Path(const Path &other) : ptr_(mg_path_copy(other.ptr_)) {}

inline Path::Path(Path &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline Path::~Path() {
  if (ptr_ != nullptr) {
    mg_path_destroy(ptr_);
  }
}

inline Path::Path(const ConstPath &path) : ptr_(mg_path_copy(path.ptr())) {}

inline ConstNode Path::GetNodeAt(size_t index) const {
  auto vertex_ptr = mg_path_node_at(ptr_, index);
  if (vertex_ptr == nullptr) {
    std::abort();
  }
  return ConstNode(vertex_ptr);
}

inline ConstUnboundRelationship Path::GetRelationshipAt(size_t index) const {
  auto edge_ptr = mg_path_relationship_at(ptr_, index);
  if (edge_ptr == nullptr) {
    std::abort();
  }
  return ConstUnboundRelationship(edge_ptr);
}

inline bool Path::IsReversedRelationshipAt(size_t index) const {
  auto is_reversed = mg_path_relationship_reversed_at(ptr_, index);
  if (is_reversed == -1) {
    std::abort();
  }
  return is_reversed == 1;
}

inline ConstPath Path::AsConstPath() const { return ConstPath(ptr_); }

inline bool Path::operator==(const Path &other) const {
  return detail::ArePathsEqual(ptr_, other.ptr_);
}

inline bool Path::operator==(const ConstPath &other) const {
  return detail::ArePathsEqual(ptr_, other.ptr());
}

inline ConstNode ConstPath::GetNodeAt(size_t index) const {
  auto vertex_ptr = mg_path_node_at(const_ptr_, index);
  if (vertex_ptr == nullptr) {
    std::abort();
  }
  return ConstNode(vertex_ptr);
}

inline ConstUnboundRelationship ConstPath::GetRelationshipAt(
    size_t index) const {
  auto edge_ptr = mg_path_relationship_at(const_ptr_, index);
  if (edge_ptr == nullptr) {
    std::abort();
  }
  return ConstUnboundRelationship(edge_ptr);
}

inline bool ConstPath::IsReversedRelationshipAt(size_t index) const {
  auto is_reversed = mg_path_relationship_reversed_at(const_ptr_, index);
  if (is_reversed == -1) {
    std::abort();
  }
  return is_reversed == 1;
}

inline bool ConstPath::operator==(const ConstPath &other) const {
  return detail::ArePathsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstPath::operator==(const Path &other) const {
  return detail::ArePathsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Date:

inline Date::Date(const Date &other) : ptr_(mg_date_copy(other.ptr_)) {}

inline Date::Date(Date &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline Date &Date::operator=(const Date &other) {
  ptr_ = mg_date_copy(other.ptr_);
  return *this;
}

inline Date &Date::operator=(Date &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline Date::~Date() {
  if (ptr_ != nullptr) {
    mg_date_destroy(ptr_);
  }
}

inline Date::Date(const ConstDate &date) : ptr_(mg_date_copy(date.ptr())) {}

inline ConstDate Date::AsConstDate() const { return ConstDate(ptr_); }

inline bool Date::operator==(const Date &other) const {
  return detail::AreDatesEqual(ptr_, other.ptr_);
}

inline bool Date::operator==(const ConstDate &other) const {
  return detail::AreDatesEqual(ptr_, other.ptr());
}

inline bool ConstDate::operator==(const ConstDate &other) const {
  return detail::AreDatesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstDate::operator==(const Date &other) const {
  return detail::AreDatesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Time:

inline Time::Time(const Time &other) : ptr_(mg_time_copy(other.ptr_)) {}

inline Time::Time(Time &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline Time &Time::operator=(const Time &other) {
  ptr_ = mg_time_copy(other.ptr_);
  return *this;
}

inline Time &Time::operator=(Time &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline Time::~Time() {
  if (ptr_ != nullptr) {
    mg_time_destroy(ptr_);
  }
}

inline Time::Time(const ConstTime &time) : ptr_(mg_time_copy(time.ptr())) {}

inline ConstTime Time::AsConstTime() const { return ConstTime(ptr_); }

inline bool Time::operator==(const Time &other) const {
  return detail::AreTimesEqual(ptr_, other.ptr_);
}

inline bool Time::operator==(const ConstTime &other) const {
  return detail::AreTimesEqual(ptr_, other.ptr());
}

inline bool ConstTime::operator==(const ConstTime &other) const {
  return detail::AreTimesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstTime::operator==(const Time &other) const {
  return detail::AreTimesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// LocalTime:

inline LocalTime::LocalTime(const LocalTime &other)
    : ptr_(mg_local_time_copy(other.ptr_)) {}

inline LocalTime::LocalTime(LocalTime &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline LocalTime &LocalTime::operator=(const LocalTime &other) {
  ptr_ = mg_local_time_copy(other.ptr_);
  return *this;
}

inline LocalTime &LocalTime::operator=(LocalTime &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline LocalTime::~LocalTime() {
  if (ptr_ != nullptr) {
    mg_local_time_destroy(ptr_);
  }
}

inline LocalTime::LocalTime(const ConstLocalTime &local_time)
    : ptr_(mg_local_time_copy(local_time.ptr())) {}

inline ConstLocalTime LocalTime::AsConstLocalTime() const {
  return ConstLocalTime(ptr_);
}

inline bool LocalTime::operator==(const LocalTime &other) const {
  return detail::AreLocalTimesEqual(ptr_, other.ptr_);
}

inline bool LocalTime::operator==(const ConstLocalTime &other) const {
  return detail::AreLocalTimesEqual(ptr_, other.ptr());
}

inline bool ConstLocalTime::operator==(const ConstLocalTime &other) const {
  return detail::AreLocalTimesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstLocalTime::operator==(const LocalTime &other) const {
  return detail::AreLocalTimesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// DateTime:

inline DateTime::DateTime(const DateTime &other)
    : ptr_(mg_date_time_copy(other.ptr_)) {}

inline DateTime::DateTime(DateTime &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline DateTime &DateTime::operator=(const DateTime &other) {
  ptr_ = mg_date_time_copy(other.ptr_);
  return *this;
}

inline DateTime &DateTime::operator=(DateTime &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline DateTime::~DateTime() {
  if (ptr_ != nullptr) {
    mg_date_time_destroy(ptr_);
  }
}

inline DateTime::DateTime(const ConstDateTime &date_time)
    : ptr_(mg_date_time_copy(date_time.ptr())) {}

inline ConstDateTime DateTime::AsConstDateTime() const {
  return ConstDateTime(ptr_);
}

inline bool DateTime::operator==(const DateTime &other) const {
  return detail::AreDateTimesEqual(ptr_, other.ptr_);
}

inline bool DateTime::operator==(const ConstDateTime &other) const {
  return detail::AreDateTimesEqual(ptr_, other.ptr());
}

inline bool ConstDateTime::operator==(const ConstDateTime &other) const {
  return detail::AreDateTimesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstDateTime::operator==(const DateTime &other) const {
  return detail::AreDateTimesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// DateTimeZoneId:

inline DateTimeZoneId::DateTimeZoneId(const DateTimeZoneId &other)
    : ptr_(mg_date_time_zone_id_copy(other.ptr_)) {}

inline DateTimeZoneId::DateTimeZoneId(DateTimeZoneId &&other)
    : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline DateTimeZoneId &DateTimeZoneId::operator=(const DateTimeZoneId &other) {
  ptr_ = mg_date_time_zone_id_copy(other.ptr_);
  return *this;
}

inline DateTimeZoneId &DateTimeZoneId::operator=(DateTimeZoneId &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline DateTimeZoneId::~DateTimeZoneId() {
  if (ptr_ != nullptr) {
    mg_date_time_zone_id_destroy(ptr_);
  }
}

inline DateTimeZoneId::DateTimeZoneId(
    const ConstDateTimeZoneId &date_time_zone_id)
    : ptr_(mg_date_time_zone_id_copy(date_time_zone_id.ptr())) {}

inline ConstDateTimeZoneId DateTimeZoneId::AsConstDateTimeZoneId() const {
  return ConstDateTimeZoneId(ptr_);
}

inline bool DateTimeZoneId::operator==(const DateTimeZoneId &other) const {
  return detail::AreDateTimeZoneIdsEqual(ptr_, other.ptr_);
}

inline bool DateTimeZoneId::operator==(const ConstDateTimeZoneId &other) const {
  return detail::AreDateTimeZoneIdsEqual(ptr_, other.ptr());
}

inline bool ConstDateTimeZoneId::operator==(
    const ConstDateTimeZoneId &other) const {
  return detail::AreDateTimeZoneIdsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstDateTimeZoneId::operator==(const DateTimeZoneId &other) const {
  return detail::AreDateTimeZoneIdsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// LocalDateTime:

inline LocalDateTime::LocalDateTime(const LocalDateTime &other)
    : ptr_(mg_local_date_time_copy(other.ptr_)) {}

inline LocalDateTime::LocalDateTime(LocalDateTime &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline LocalDateTime &LocalDateTime::operator=(const LocalDateTime &other) {
  ptr_ = mg_local_date_time_copy(other.ptr_);
  return *this;
}

inline LocalDateTime &LocalDateTime::operator=(LocalDateTime &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline LocalDateTime::~LocalDateTime() {
  if (ptr_ != nullptr) {
    mg_local_date_time_destroy(ptr_);
  }
}

inline LocalDateTime::LocalDateTime(const ConstLocalDateTime &local_date_time)
    : ptr_(mg_local_date_time_copy(local_date_time.ptr())) {}

inline ConstLocalDateTime LocalDateTime::AsConstLocalDateTime() const {
  return ConstLocalDateTime(ptr_);
}

inline bool LocalDateTime::operator==(const LocalDateTime &other) const {
  return detail::AreLocalDateTimesEqual(ptr_, other.ptr_);
}

inline bool LocalDateTime::operator==(const ConstLocalDateTime &other) const {
  return detail::AreLocalDateTimesEqual(ptr_, other.ptr());
}

inline bool ConstLocalDateTime::operator==(
    const ConstLocalDateTime &other) const {
  return detail::AreLocalDateTimesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstLocalDateTime::operator==(const LocalDateTime &other) const {
  return detail::AreLocalDateTimesEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Duration:

inline Duration::Duration(const Duration &other)
    : ptr_(mg_duration_copy(other.ptr_)) {}

inline Duration::Duration(Duration &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline Duration &Duration::operator=(const Duration &other) {
  ptr_ = mg_duration_copy(other.ptr_);
  return *this;
}

inline Duration &Duration::operator=(Duration &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline Duration::~Duration() {
  if (ptr_ != nullptr) {
    mg_duration_destroy(ptr_);
  }
}

inline Duration::Duration(const ConstDuration &duration)
    : ptr_(mg_duration_copy(duration.ptr())) {}

inline ConstDuration Duration::AsConstDuration() const {
  return ConstDuration(ptr_);
}

inline bool Duration::operator==(const Duration &other) const {
  return detail::AreDurationsEqual(ptr_, other.ptr_);
}

inline bool Duration::operator==(const ConstDuration &other) const {
  return detail::AreDurationsEqual(ptr_, other.ptr());
}

inline bool ConstDuration::operator==(const ConstDuration &other) const {
  return detail::AreDurationsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstDuration::operator==(const Duration &other) const {
  return detail::AreDurationsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Point2d:

inline Point2d::Point2d(const Point2d &other)
    : ptr_(mg_point_2d_copy(other.ptr_)) {}

inline Point2d::Point2d(Point2d &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline Point2d &Point2d::operator=(const Point2d &other) {
  ptr_ = mg_point_2d_copy(other.ptr_);
  return *this;
}

inline Point2d &Point2d::operator=(Point2d &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline Point2d::~Point2d() {
  if (ptr_ != nullptr) {
    mg_point_2d_destroy(ptr_);
  }
}

inline Point2d::Point2d(const ConstPoint2d &point_2d)
    : ptr_(mg_point_2d_copy(point_2d.ptr())) {}

inline ConstPoint2d Point2d::AsConstPoint2d() const {
  return ConstPoint2d(ptr_);
}

inline bool Point2d::operator==(const Point2d &other) const {
  return detail::ArePoint2dsEqual(ptr_, other.ptr_);
}

inline bool Point2d::operator==(const ConstPoint2d &other) const {
  return detail::ArePoint2dsEqual(ptr_, other.ptr());
}

inline bool ConstPoint2d::operator==(const ConstPoint2d &other) const {
  return detail::ArePoint2dsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstPoint2d::operator==(const Point2d &other) const {
  return detail::ArePoint2dsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Point3d:

inline Point3d::Point3d(const Point3d &other)
    : ptr_(mg_point_3d_copy(other.ptr_)) {}

inline Point3d::Point3d(Point3d &&other) : ptr_(other.ptr_) {
  other.ptr_ = nullptr;
}

inline Point3d &Point3d::operator=(const Point3d &other) {
  ptr_ = mg_point_3d_copy(other.ptr_);
  return *this;
}

inline Point3d &Point3d::operator=(Point3d &&other) {
  ptr_ = other.ptr_;
  other.ptr_ = nullptr;
  return *this;
}

inline Point3d::~Point3d() {
  if (ptr_ != nullptr) {
    mg_point_3d_destroy(ptr_);
  }
}

inline Point3d::Point3d(const ConstPoint3d &point_3d)
    : ptr_(mg_point_3d_copy(point_3d.ptr())) {}

inline ConstPoint3d Point3d::AsConstPoint3d() const {
  return ConstPoint3d(ptr_);
}

inline bool Point3d::operator==(const Point3d &other) const {
  return detail::ArePoint3dsEqual(ptr_, other.ptr_);
}

inline bool Point3d::operator==(const ConstPoint3d &other) const {
  return detail::ArePoint3dsEqual(ptr_, other.ptr());
}

inline bool ConstPoint3d::operator==(const ConstPoint3d &other) const {
  return detail::ArePoint3dsEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstPoint3d::operator==(const Point3d &other) const {
  return detail::ArePoint3dsEqual(const_ptr_, other.ptr());
}

////////////////////////////////////////////////////////////////////////////////
// Value:

inline Value::Value(const Value &other) : Value(mg_value_copy(other.ptr_)) {}

inline Value::Value(Value &&other) : ptr_(other.ptr_) { other.ptr_ = nullptr; }

inline Value::~Value() {
  if (ptr_ != nullptr) {
    mg_value_destroy(ptr_);
  }
}

inline Value::Value(const ConstValue &value)
    : ptr_(mg_value_copy(value.ptr())) {}

inline Value::Value(const std::string_view value)
    : Value(
          mg_value_make_string2(mg_string_make2(value.size(), value.data()))) {}

inline Value::Value(const char *value) : Value(mg_value_make_string(value)) {}

inline Value::Value(List &&list) : Value(mg_value_make_list(list.ptr_)) {
  list.ptr_ = nullptr;
}

inline Value::Value(Map &&map) : Value(mg_value_make_map(map.ptr_)) {
  map.ptr_ = nullptr;
}

inline Value::Value(Node &&vertex) : Value(mg_value_make_node(vertex.ptr_)) {
  vertex.ptr_ = nullptr;
}

inline Value::Value(Relationship &&edge)
    : Value(mg_value_make_relationship(edge.ptr_)) {
  edge.ptr_ = nullptr;
}

inline Value::Value(UnboundRelationship &&edge)
    : Value(mg_value_make_unbound_relationship(edge.ptr_)) {
  edge.ptr_ = nullptr;
}

inline Value::Value(Path &&path) : Value(mg_value_make_path(path.ptr_)) {
  path.ptr_ = nullptr;
}

inline Value::Value(Date &&date) : Value(mg_value_make_date(date.ptr_)) {
  date.ptr_ = nullptr;
}

inline Value::Value(Time &&time) : Value(mg_value_make_time(time.ptr_)) {
  time.ptr_ = nullptr;
}

inline Value::Value(LocalTime &&local_time)
    : Value(mg_value_make_local_time(local_time.ptr_)) {
  local_time.ptr_ = nullptr;
}

inline Value::Value(DateTime &&date_time)
    : Value(mg_value_make_date_time(date_time.ptr_)) {
  date_time.ptr_ = nullptr;
}

inline Value::Value(DateTimeZoneId &&date_time_zone_id)
    : Value(mg_value_make_date_time_zone_id(date_time_zone_id.ptr_)) {
  date_time_zone_id.ptr_ = nullptr;
}

inline Value::Value(LocalDateTime &&local_date_time)
    : Value(mg_value_make_local_date_time(local_date_time.ptr_)) {
  local_date_time.ptr_ = nullptr;
}

inline Value::Value(Duration &&duration)
    : Value(mg_value_make_duration(duration.ptr_)) {
  duration.ptr_ = nullptr;
}

inline Value::Value(Point2d &&point_2d)
    : Value(mg_value_make_point_2d(point_2d.ptr_)) {
  point_2d.ptr_ = nullptr;
}

inline Value::Value(Point3d &&point_3d)
    : Value(mg_value_make_point_3d(point_3d.ptr_)) {
  point_3d.ptr_ = nullptr;
}

inline bool Value::ValueBool() const {
  if (type() != Type::Bool) {
    std::abort();
  }
  return static_cast<bool>(mg_value_bool(ptr_));
}

inline int64_t Value::ValueInt() const {
  if (type() != Type::Int) {
    std::abort();
  }
  return mg_value_integer(ptr_);
}

inline double Value::ValueDouble() const {
  if (type() != Type::Double) {
    std::abort();
  }
  return mg_value_float(ptr_);
}

inline std::string_view Value::ValueString() const {
  if (type() != Type::String) {
    std::abort();
  }
  return detail::ConvertString(mg_value_string(ptr_));
}

inline const ConstList Value::ValueList() const {
  if (type() != Type::List) {
    std::abort();
  }
  return ConstList(mg_value_list(ptr_));
}

inline const ConstMap Value::ValueMap() const {
  if (type() != Type::Map) {
    std::abort();
  }
  return ConstMap(mg_value_map(ptr_));
}

inline const ConstNode Value::ValueNode() const {
  if (type() != Type::Node) {
    std::abort();
  }
  return ConstNode(mg_value_node(ptr_));
}

inline const ConstRelationship Value::ValueRelationship() const {
  if (type() != Type::Relationship) {
    std::abort();
  }
  return ConstRelationship(mg_value_relationship(ptr_));
}

inline const ConstUnboundRelationship Value::ValueUnboundRelationship() const {
  if (type() != Type::UnboundRelationship) {
    std::abort();
  }
  return ConstUnboundRelationship(mg_value_unbound_relationship(ptr_));
}

inline const ConstPath Value::ValuePath() const {
  if (type() != Type::Path) {
    std::abort();
  }
  return ConstPath(mg_value_path(ptr_));
}

inline const ConstDate Value::ValueDate() const {
  if (type() != Type::Date) {
    std::abort();
  }
  return ConstDate(mg_value_date(ptr_));
}

inline const ConstTime Value::ValueTime() const {
  if (type() != Type::Time) {
    std::abort();
  }
  return ConstTime(mg_value_time(ptr_));
}

inline const ConstLocalTime Value::ValueLocalTime() const {
  if (type() != Type::LocalTime) {
    std::abort();
  }
  return ConstLocalTime(mg_value_local_time(ptr_));
}

inline const ConstDateTime Value::ValueDateTime() const {
  if (type() != Type::DateTime) {
    std::abort();
  }
  return ConstDateTime(mg_value_date_time(ptr_));
}

inline const ConstDateTimeZoneId Value::ValueDateTimeZoneId() const {
  if (type() != Type::DateTimeZoneId) {
    std::abort();
  }
  return ConstDateTimeZoneId(mg_value_date_time_zone_id(ptr_));
}

inline const ConstLocalDateTime Value::ValueLocalDateTime() const {
  if (type() != Type::LocalDateTime) {
    std::abort();
  }
  return ConstLocalDateTime(mg_value_local_date_time(ptr_));
}

inline const ConstDuration Value::ValueDuration() const {
  if (type() != Type::Duration) {
    std::abort();
  }
  return ConstDuration(mg_value_duration(ptr_));
}

inline const ConstPoint2d Value::ValuePoint2d() const {
  if (type() != Type::Point2d) {
    std::abort();
  }
  return ConstPoint2d(mg_value_point_2d(ptr_));
}

inline const ConstPoint3d Value::ValuePoint3d() const {
  if (type() != Type::Point3d) {
    std::abort();
  }
  return ConstPoint3d(mg_value_point_3d(ptr_));
}

inline Value::Type Value::type() const {
  return detail::ConvertType(mg_value_get_type(ptr_));
}

inline ConstValue Value::AsConstValue() const { return ConstValue(ptr_); }

inline bool Value::operator==(const Value &other) const {
  return detail::AreValuesEqual(ptr_, other.ptr_);
}

inline bool Value::operator==(const ConstValue &other) const {
  return detail::AreValuesEqual(ptr_, other.ptr());
}

inline bool ConstValue::ValueBool() const {
  if (type() != Value::Type::Bool) {
    std::abort();
  }
  return static_cast<bool>(mg_value_bool(const_ptr_));
}

inline int64_t ConstValue::ValueInt() const {
  if (type() != Value::Type::Int) {
    std::abort();
  }
  return mg_value_integer(const_ptr_);
}

inline double ConstValue::ValueDouble() const {
  if (type() != Value::Type::Double) {
    std::abort();
  }
  return mg_value_float(const_ptr_);
}

inline std::string_view ConstValue::ValueString() const {
  if (type() != Value::Type::String) {
    std::abort();
  }
  return detail::ConvertString(mg_value_string(const_ptr_));
}

inline const ConstList ConstValue::ValueList() const {
  if (type() != Value::Type::List) {
    std::abort();
  }
  return ConstList(mg_value_list(const_ptr_));
}

inline const ConstMap ConstValue::ValueMap() const {
  if (type() != Value::Type::Map) {
    std::abort();
  }
  return ConstMap(mg_value_map(const_ptr_));
}

inline const ConstNode ConstValue::ValueNode() const {
  if (type() != Value::Type::Node) {
    std::abort();
  }
  return ConstNode(mg_value_node(const_ptr_));
}

inline const ConstRelationship ConstValue::ValueRelationship() const {
  if (type() != Value::Type::Relationship) {
    std::abort();
  }
  return ConstRelationship(mg_value_relationship(const_ptr_));
}

inline const ConstUnboundRelationship ConstValue::ValueUnboundRelationship()
    const {
  if (type() != Value::Type::UnboundRelationship) {
    std::abort();
  }
  return ConstUnboundRelationship(mg_value_unbound_relationship(const_ptr_));
}

inline const ConstPath ConstValue::ValuePath() const {
  if (type() != Value::Type::Path) {
    std::abort();
  }
  return ConstPath(mg_value_path(const_ptr_));
}

inline Value::Type ConstValue::type() const {
  return detail::ConvertType(mg_value_get_type(const_ptr_));
}

inline const ConstDate ConstValue::ValueDate() const {
  if (type() != Value::Type::Date) {
    std::abort();
  }
  return ConstDate(mg_value_date(const_ptr_));
}

inline const ConstTime ConstValue::ValueTime() const {
  if (type() != Value::Type::Time) {
    std::abort();
  }
  return ConstTime(mg_value_time(const_ptr_));
}

inline const ConstLocalTime ConstValue::ValueLocalTime() const {
  if (type() != Value::Type::LocalTime) {
    std::abort();
  }
  return ConstLocalTime(mg_value_local_time(const_ptr_));
}

inline const ConstDateTime ConstValue::ValueDateTime() const {
  if (type() != Value::Type::DateTime) {
    std::abort();
  }
  return ConstDateTime(mg_value_date_time(const_ptr_));
}

inline const ConstDateTimeZoneId ConstValue::ValueDateTimeZoneId() const {
  if (type() != Value::Type::DateTimeZoneId) {
    std::abort();
  }
  return ConstDateTimeZoneId(mg_value_date_time_zone_id(const_ptr_));
}

inline const ConstLocalDateTime ConstValue::ValueLocalDateTime() const {
  if (type() != Value::Type::LocalDateTime) {
    std::abort();
  }
  return ConstLocalDateTime(mg_value_local_date_time(const_ptr_));
}

inline const ConstDuration ConstValue::ValueDuration() const {
  if (type() != Value::Type::Duration) {
    std::abort();
  }
  return ConstDuration(mg_value_duration(const_ptr_));
}

inline const ConstPoint2d ConstValue::ValuePoint2d() const {
  if (type() != Value::Type::Point2d) {
    std::abort();
  }
  return ConstPoint2d(mg_value_point_2d(const_ptr_));
}

inline const ConstPoint3d ConstValue::ValuePoint3d() const {
  if (type() != Value::Type::Point3d) {
    std::abort();
  }
  return ConstPoint3d(mg_value_point_3d(const_ptr_));
}

inline bool ConstValue::operator==(const ConstValue &other) const {
  return detail::AreValuesEqual(const_ptr_, other.const_ptr_);
}

inline bool ConstValue::operator==(const Value &other) const {
  return detail::AreValuesEqual(const_ptr_, other.ptr());
}

}  // namespace mg