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
use enum_from_str::ParseEnumVariantError;
use enum_from_str_derive::FromStr;
use msoffice_shared::error::{MissingAttributeError, MissingChildNodeError, NotGroupMemberError, XmlError};
use msoffice_shared::relationship::RelationshipId;
use msoffice_shared::xml::{parse_xml_bool, XmlNode};
use msoffice_shared::drawingml;
use std::io::Read;
use zip::read::ZipFile;

use super::animation::{Build, TimeNodeGroup};
use super::presentation::{CustomerDataList, SlideLayoutIdListEntry};

pub type Result<T> = ::std::result::Result<T, Box<dyn (::std::error::Error)>>;

/// This simple type facilitates the storing of the content type a placeholder should contain.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum PlaceholderType {
    /// Contains a slide title. Allowed for Slide, Slide Layout and Slide Master. Can be horizontal or vertical on Slide
    /// and Slide Layout.
    #[from_str = "title"]
    Title,
    /// Contains body text. Allowed for Slide, Slide Layout, Slide Master, Notes, Notes Master. Can be horizontal
    /// or vertical on Slide and Slide Layout.
    #[from_str = "body"]
    Body,
    /// Contains a title intended to be centered on the slide. Allowed for Slide and Slide Layout.
    #[from_str = "ctrTitle"]
    CenteredTitle,
    /// Contains a subtitle. Allowed for Slide and Slide Layout.
    #[from_str = "subTitle"]
    SubTitle,
    /// Contains the date and time. Allowed for Slide, Slide Layout, Slide Master, Notes, Notes Master, Handout Master
    #[from_str = "dt"]
    DateTime,
    /// Contains the number of a slide. Allowed for Slide, Slide Layout, Slide Master, Notes, Notes Master, Handout
    /// Master
    #[from_str = "sldNum"]
    SlideNumber,
    /// Contains text to be used as a footer in the document. Allowed for Slide, Slide Layout, Slide Master, Notes,
    /// Notes Master, Handout Master
    #[from_str = "ftr"]
    Footer,
    /// Contains text to be used as a header for the document. Allowed for Notes, Notes Master, Handout Master.
    #[from_str = "hdr"]
    Header,
    /// Contains any content type. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "obj"]
    Object,
    /// Contains a chart or graph. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "chart"]
    Chart,
    /// Contains a table. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "tbl"]
    Table,
    /// Contains a single clip art image. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "clipArt"]
    ClipArt,
    /// Contains a diagram. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "dgm"]
    Diagram,
    /// Contains multimedia content such as audio or a movie clip. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "media"]
    Media,
    /// Contains an image of the slide. Allowed for Notes and Notes Master.
    #[from_str = "sldImg"]
    SlideImage,
    /// Contains a picture. Special type. Allowed for Slide and Slide Layout.
    #[from_str = "pic"]
    Picture,
}

/// This simple type defines a direction of either horizontal or vertical.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum Direction {
    /// Defines a horizontal direction.
    #[from_str = "horz"]
    Horizontal,
    /// Defines a vertical direction.
    #[from_str = "vert"]
    Vertical,
}

/// This simple type facilitates the storing of the size of the placeholder. This size is described relative to the body
/// placeholder on the master.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum PlaceholderSize {
    /// Specifies that the placeholder should take the full size of the body placeholder on the master.
    #[from_str = "full"]
    Full,
    /// Specifies that the placeholder should take the half size of the body placeholder on the master. Half size
    /// vertically or horizontally? Needs a picture.
    #[from_str = "half"]
    Half,
    /// Specifies that the placeholder should take a quarter of the size of the body placeholder on the master. Picture
    /// would be helpful
    #[from_str = "quarter"]
    Quarter,
}

/// This simple type defines a set of slide transition directions.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum TransitionSideDirectionType {
    /// Specifies that the transition direction is left
    #[from_str = "l"]
    Left,
    /// Specifies that the transition direction is up
    #[from_str = "u"]
    Up,
    /// Specifies that the transition direction is right
    #[from_str = "r"]
    Right,
    /// Specifies that the transition direction is down
    #[from_str = "d"]
    Down,
}

/// This simple type specifies diagonal directions for slide transitions.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum TransitionCornerDirectionType {
    /// Specifies the slide transition direction of left-up
    #[from_str = "lu"]
    LeftUp,
    /// Specifies the slide transition direction of right-up
    #[from_str = "ru"]
    RightUp,
    /// Specifies the slide transition direction of left-down
    #[from_str = "ld"]
    LeftDown,
    /// Specifies the slide transition direction of right-down
    #[from_str = "rd"]
    RightDown,
}

/// This simple type specifies the direction of an animation.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum TransitionEightDirectionType {
    /// Specifies that the transition direction is left
    #[from_str = "l"]
    Left,
    /// Specifies that the transition direction is up
    #[from_str = "u"]
    Up,
    /// Specifies that the transition direction is right
    #[from_str = "r"]
    Right,
    /// Specifies that the transition direction is down
    #[from_str = "d"]
    Down,
    /// Specifies the slide transition direction of left-up
    #[from_str = "lu"]
    LeftUp,
    /// Specifies the slide transition direction of right-up
    #[from_str = "ru"]
    RightUp,
    /// Specifies the slide transition direction of left-down
    #[from_str = "ld"]
    LeftDown,
    /// Specifies the slide transition direction of right-down
    #[from_str = "rd"]
    RightDown,
}

/// This simple type specifies if a slide transition should go in or out.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum TransitionInOutDirectionType {
    /// Specifies the slide transition should go in
    #[from_str = "in"]
    In,
    /// Specifies the slide transition should go out
    #[from_str = "out"]
    Out,
}

/// This simple type defines the allowed transition speeds for transitioning from the current slide to the next.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum TransitionSpeed {
    /// Slow slide transition.
    #[from_str = "slow"]
    Slow,
    /// Medium slide transition.
    #[from_str = "med"]
    Medium,
    /// Fast slide transition.
    #[from_str = "fast"]
    Fast,
}

/// This simple type defines an arrangement of content on a slide. Each layout type is not tied to an exact
/// positioning of placeholders, but rather provides a higher-level description of the content type and positioning of
/// placeholders. This information can be used by the application to aid in mapping between different layouts. The
/// application can choose which, if any, of these layouts to make available through its user interface.
///
/// Each layout contains zero or more placeholders, each with a specific content type. An "object" placeholder can
/// contain any kind of data. Media placeholders are intended to hold video or audio clips. The enumeration value
/// descriptions include illustrations of sample layouts for each value of the simple type.
#[derive(Debug, Clone, Copy, PartialEq, FromStr)]
pub enum SlideLayoutType {
    /// Blank
    #[from_str = "blank"]
    Blank,
    /// Title and chart
    #[from_str = "chart"]
    Chart,
    /// Title, chart on left and text on right
    #[from_str = "chartAndTx"]
    ChartAndText,
    /// Title, clipart on left, text on right
    #[from_str = "clipArtAndTx"]
    ClipArtAndText,
    /// Title, clip art on left, vertical text on right
    #[from_str = "clipArtAndVertTx"]
    ClipArtAndVerticalText,
    /// Custom layout defined by user
    #[from_str = "cust"]
    Custom,
    /// Title and diagram
    #[from_str = "dgm"]
    Diagram,
    /// Title and four objects
    #[from_str = "fourObj"]
    FourObjects,
    /// Title, media on left, text on right
    #[from_str = "mediaAndTx"]
    MediaAndText,
    /// Title and object
    #[from_str = "obj"]
    Object,
    /// Title, one object on left, two objects on right
    #[from_str = "objAndTwoObj"]
    ObjectAndTwoObject,
    /// Title, object on left, text on right
    #[from_str = "objAndTx"]
    ObjectAndText,
    /// Object only
    #[from_str = "objOnly"]
    ObjectOnly,
    /// Title, object on top, text on bottom
    #[from_str = "objOverTx"]
    ObjectOverText,
    /// Title, object and caption text
    #[from_str = "objTx"]
    ObjectText,
    /// Title, picture, and caption text
    #[from_str = "picTx"]
    PictureText,
    /// Section header title and subtitle text
    #[from_str = "secHead"]
    SectionHeader,
    /// Title and table
    #[from_str = "tbl"]
    Table,
    /// Title layout with centered title and subtitle placeholders
    #[from_str = "title"]
    Title,
    /// Title only
    #[from_str = "titleOnly"]
    TitleOnly,
    /// Title, text on left, text on right
    #[from_str = "twoColTx"]
    TwoColumnText,
    /// Title, object on left, object on right
    #[from_str = "twoObj"]
    TwoObject,
    /// Title, two objects on left, one object on right
    #[from_str = "twoObjAndObj"]
    TwoObjectsAndObject,
    /// Title, two objects on left, text on right
    #[from_str = "twoObjAndTx"]
    TwoObjectsAndText,
    /// Title, two objects on top, text on bottom
    #[from_str = "twoObjOverTx"]
    TwoObjectsOverText,
    /// Title, two objects each with text
    #[from_str = "twoTxTwoObj"]
    TwoTextTwoObjects,
    /// Title and text
    #[from_str = "tx"]
    Text,
    /// Title, text on left and chart on right
    #[from_str = "txAndChart"]
    TextAndChart,
    /// Title, text on left, clip art on right
    #[from_str = "txAndClipArt"]
    TextAndClipArt,
    /// Title, text on left, media on right
    #[from_str = "txAndMedia"]
    TextAndMedia,
    /// Title, text on left, object on right
    #[from_str = "txAndObj"]
    TextAndObject,
    /// Title, text on left, two objects on right
    #[from_str = "txAndTwoObj"]
    TextAndTwoObjects,
    /// Title, text on top, object on bottom
    #[from_str = "txOverObj"]
    TextOverObject,
    /// Vertical title on right, vertical text on left
    #[from_str = "vertTitleAndTx"]
    VerticalTitleAndText,
    /// Vertical title on right, vertical text on top, chart on bottom
    #[from_str = "vertTitleAndTxOverChart"]
    VerticalTitleAndTextOverChart,
    /// Title and vertical text body
    #[from_str = "vertTx"]
    VerticalText,
}

/// This element specifies an instance of a slide master slide. Within a slide master slide are contained all elements
/// that describe the objects and their corresponding formatting for within a presentation slide. Within a slide
/// master slide are two main elements. The common_slide_data element specifies the common slide elements such as shapes and
/// their attached text bodies. Then the text_styles element specifies the formatting for the text within each of these
/// shapes. The other properties within a slide master slide specify other properties for within a presentation slide
/// such as color information, headers and footers, as well as timing and transition information for all corresponding
/// presentation slides.
#[derive(Debug, Clone)]
pub struct SlideMaster {
    /// Specifies whether the corresponding slide layout is deleted when all the slides that follow
    /// that layout are deleted. If this attribute is not specified then a value of false should be
    /// assumed by the generating application. This would mean that the slide would in fact be
    /// deleted if no slides within the presentation were related to it.
    ///
    /// Defaults to false
    pub preserve: Option<bool>,
    pub common_slide_data: Box<CommonSlideData>,
    /// This element specifies the mapping layer that transforms one color scheme definition to another. Each attribute
    /// represents a color name that can be referenced in this master, and the value is the corresponding color in the
    /// theme.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:clrMap bg1="dk1" tx1="lt1" bg2="dk2" tx2="lt2" accent1="accent1"
    /// accent2="accent2" accent3="accent3" accent4="accent4" accent5="accent5"
    /// accent6="accent6" hlink="hlink" folHlink="folHlink"/>
    /// ```
    pub color_mapping: Box<drawingml::ColorMapping>,
    /// This element specifies the existence of the slide layout identification list. This list is contained within the slide
    /// master and is used to determine which layouts are being used within the slide master file. Each layout within the
    /// list of slide layouts has its own identification number and relationship identifier that uniquely identifies it within
    /// both the presentation document and the particular master slide within which it is used.
    ///
    /// The SlideLayoutIdListEntry specifies the relationship information for each slide layout that is used within the slide master.
    /// The slide master has relationship identifiers that it uses internally for determining the slide layouts that should be
    /// used. Then, to resolve what these slide layouts should be the sldLayoutId elements in the sldLayoutIdLst are
    /// utilized.
    pub slide_layout_id_list: Option<Vec<SlideLayoutIdListEntry>>,
    /// This element specifies the kind of slide transition that should be used to transition to the current slide from the
    /// previous slide. That is, the transition information is stored on the slide that appears after the transition is
    /// complete.
    pub transition: Option<Box<SlideTransition>>,
    /// This element specifies the timing information for handling all animations and timed events within the
    /// corresponding slide. This information is tracked via time nodes within the timing element. More information on
    /// the specifics of these time nodes and how they are to be defined can be found within the Animation section of
    /// the PresentationML framework.
    pub timing: Option<SlideTiming>,
    /// This element specifies the header and footer information for a slide. Headers and footers consist of
    /// placeholders for text that should be consistent across all slides and slide types, such as a date and time, slide
    /// numbering, and custom header and footer text.
    pub header_footer: Option<HeaderFooter>,
    /// This element specifies the text styles within a slide master. Within this element is the styling information for title
    /// text, the body text and other slide text as well. This element is only for use within the Slide Master and thus sets
    /// the text styles for the corresponding presentation slides.
    pub text_styles: Option<SlideMasterTextStyles>,
}

impl SlideMaster {
    pub fn from_zip_file(zip_file: &mut ZipFile<'_>) -> Result<Self> {
        let mut xml_string = String::new();
        zip_file.read_to_string(&mut xml_string)?;
        let xml_node = XmlNode::from_str(xml_string.as_str())?;

        Self::from_xml_element(&xml_node)
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let preserve = match xml_node.attribute("preserve") {
            Some(val) => Some(parse_xml_bool(val)?),
            None => None,
        };

        let mut common_slide_data = None;
        let mut color_mapping = None;
        let mut slide_layout_id_list = None;
        let mut transition = None;
        let mut timing = None;
        let mut header_footer = None;
        let mut text_styles = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cSld" => common_slide_data = Some(Box::new(CommonSlideData::from_xml_element(child_node)?)),
                "clrMap" => {
                    color_mapping = Some(Box::new(drawingml::ColorMapping::from_xml_element(
                        child_node,
                    )?))
                }
                "sldLayoutIdLst" => {
                    let mut vec = Vec::new();
                    for slide_layout_id_node in &child_node.child_nodes {
                        vec.push(SlideLayoutIdListEntry::from_xml_element(slide_layout_id_node)?);
                    }
                    slide_layout_id_list = Some(vec);
                }
                "transition" => transition = Some(Box::new(SlideTransition::from_xml_element(child_node)?)),
                "timing" => timing = Some(SlideTiming::from_xml_element(child_node)?),
                "hf" => header_footer = Some(HeaderFooter::from_xml_element(child_node)?),
                "txStyles" => text_styles = Some(SlideMasterTextStyles::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let common_slide_data = common_slide_data
            .ok_or_else(|| XmlError::from(MissingChildNodeError::new(xml_node.name.clone(), "cSld")))?;
        let color_mapping =
            color_mapping.ok_or_else(|| XmlError::from(MissingChildNodeError::new(xml_node.name.clone(), "clrMap")))?;

        Ok(Self {
            common_slide_data,
            color_mapping,
            slide_layout_id_list,
            transition,
            timing,
            header_footer,
            text_styles,
            preserve,
        })
    }
}

/// This element specifies an instance of a slide layout. The slide layout contains in essence a template slide design
/// that can be applied to any existing slide. When applied to an existing slide all corresponding content should be
/// mapped to the new slide layout.
#[derive(Debug, Clone)]
pub struct SlideLayout {
    /// Specifies a name to be used in place of the name attribute within the cSld element. This
    /// is used for layout matching in response to layout changes and template applications.
    ///
    /// Defaults to ""
    pub matching_name: Option<String>,
    /// Specifies the slide layout type that is used by this slide.
    ///
    /// Defaults to SlideLayoutType::Custom
    pub slide_layout_type: Option<SlideLayoutType>,
    /// Specifies whether the corresponding slide layout is deleted when all the slides that follow
    /// that layout are deleted. If this attribute is not specified then a value of false should be
    /// assumed by the generating application. This would mean that the slide would in fact be
    /// deleted if no slides within the presentation were related to it.
    ///
    /// Defaults to false
    pub preserve: Option<bool>,
    /// Specifies if the corresponding object has been drawn by the user and should thus not be
    /// deleted. This allows for the flagging of slides that contain user drawn data.
    pub is_user_drawn: Option<bool>,
    /// Specifies if shapes on the master slide should be shown on slides or not.
    ///
    /// Defaults to true
    pub show_master_shapes: Option<bool>,
    /// Specifies whether or not to display animations on placeholders from the master slide.
    ///
    /// Defaults to true
    pub show_master_placeholder_animations: Option<bool>,
    pub common_slide_data: Box<CommonSlideData>,
    pub color_mapping_override: Option<drawingml::ColorMappingOverride>,
    /// This element specifies the kind of slide transition that should be used to transition to the current slide from the
    /// previous slide. That is, the transition information is stored on the slide that appears after the transition is
    /// complete.
    pub transition: Option<Box<SlideTransition>>,
    /// This element specifies the timing information for handling all animations and timed events within the
    /// corresponding slide. This information is tracked via time nodes within the timing element. More information on
    /// the specifics of these time nodes and how they are to be defined can be found within the Animation section of
    /// the PresentationML framework.
    pub timing: Option<SlideTiming>,
    pub header_footer: Option<HeaderFooter>,
}

impl SlideLayout {
    pub fn from_zip_file(zip_file: &mut ZipFile<'_>) -> Result<Self> {
        let mut xml_string = String::new();
        zip_file.read_to_string(&mut xml_string)?;
        let xml_node = XmlNode::from_str(xml_string.as_str())?;

        Self::from_xml_element(&xml_node)
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut matching_name = None;
        let mut slide_layout_type = None;
        let mut preserve = None;
        let mut is_user_drawn = None;
        let mut show_master_shapes = None;
        let mut show_master_placeholder_animations = None;

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "matchingName" => matching_name = Some(value.clone()),
                "type" => slide_layout_type = Some(value.parse()?),
                "preserve" => preserve = Some(parse_xml_bool(value)?),
                "userDrawn" => is_user_drawn = Some(parse_xml_bool(value)?),
                "showMasterSp" => show_master_shapes = Some(parse_xml_bool(value)?),
                "showMasterPhAnim" => show_master_placeholder_animations = Some(parse_xml_bool(value)?),
                _ => (),
            }
        }

        let mut common_slide_data = None;
        let mut color_mapping_override = None;
        let mut transition = None;
        let mut timing = None;
        let mut header_footer = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cSld" => common_slide_data = Some(Box::new(CommonSlideData::from_xml_element(child_node)?)),
                "clrMapOvr" => {
                    let clr_map_node = child_node.child_nodes.get(0).ok_or_else(|| {
                        MissingChildNodeError::new(child_node.name.clone(), "masterClrMapping|overrideClrMapping")
                    })?;
                    color_mapping_override = Some(drawingml::ColorMappingOverride::from_xml_element(
                        clr_map_node,
                    )?);
                }
                "transition" => transition = Some(Box::new(SlideTransition::from_xml_element(child_node)?)),
                "timing" => timing = Some(SlideTiming::from_xml_element(child_node)?),
                "hf" => header_footer = Some(HeaderFooter::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let common_slide_data =
            common_slide_data.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cSld"))?;

        Ok(Self {
            matching_name,
            slide_layout_type,
            preserve,
            is_user_drawn,
            show_master_shapes,
            show_master_placeholder_animations,
            common_slide_data,
            color_mapping_override,
            transition,
            timing,
            header_footer,
        })
    }
}

/// This element specifies a slide within a slide list. The slide list is used to specify an ordering of slides.
///
/// # Xml example
///
/// ```xml
/// <p:custShowLst>
///   <p:custShow name="Custom Show 1" id="0">
///     <p:sldLst>
///       <p:sld r:id="rId4"/>
///       <p:sld r:id="rId3"/>
///       <p:sld r:id="rId2"/>
///       <p:sld r:id="rId5"/>
///     </p:sldLst>
///   </p:custShow>
/// </p:custShowLst>
/// ```
/// In the above example the order specified to present the slides is slide 4, then 3, 2 and finally 5.
#[derive(Debug, Clone)]
pub struct Slide {
    /// Specifies that the current slide should be shown in slide show. If this attribute is omitted
    /// then a value of true is assumed.
    ///
    /// Defaults to true
    pub show: Option<bool>,
    /// Specifies if shapes on the master slide should be shown on slides or not.
    ///
    /// Defaults to true
    pub show_master_shapes: Option<bool>,
    /// Specifies whether or not to display animations on placeholders from the master slide.
    ///
    /// Defaults to true
    pub show_master_placeholder_animations: Option<bool>,
    pub common_slide_data: Box<CommonSlideData>,
    /// This element provides a mechanism with which to override the color schemes listed within the
    /// SlideMaster::color_mapping element.
    /// If the ColorMappingOverride::UseMaster element is present, the color scheme defined by the master is used.
    /// If the ColorMappingOverride::Override element is present, it defines a new color scheme specific to the
    /// parent notes slide, presentation slide, or slide layout.
    pub color_mapping_override: Option<drawingml::ColorMappingOverride>,
    /// This element specifies the kind of slide transition that should be used to transition to the current slide from the
    /// previous slide. That is, the transition information is stored on the slide that appears after the transition is
    /// complete.
    pub transition: Option<Box<SlideTransition>>,
    /// This element specifies the timing information for handling all animations and timed events within the
    /// corresponding slide. This information is tracked via time nodes within the timing element. More information on
    /// the specifics of these time nodes and how they are to be defined can be found within the Animation section of
    /// the PresentationML framework.
    pub timing: Option<SlideTiming>,
}

impl Slide {
    pub fn from_zip_file(zip_file: &mut ZipFile<'_>) -> Result<Self> {
        let mut xml_string = String::new();
        zip_file.read_to_string(&mut xml_string)?;
        let xml_node = XmlNode::from_str(xml_string.as_str())?;

        Self::from_xml_element(&xml_node)
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut show = None;
        let mut show_master_shapes = None;
        let mut show_master_placeholder_animations = None;

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "show" => show = Some(parse_xml_bool(value)?),
                "showMasterSp" => show_master_shapes = Some(parse_xml_bool(value)?),
                "showMasterPhAnim" => show_master_placeholder_animations = Some(parse_xml_bool(value)?),
                _ => (),
            }
        }

        let mut common_slide_data = None;
        let mut color_mapping_override = None;
        let mut transition = None;
        let mut timing = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cSld" => common_slide_data = Some(Box::new(CommonSlideData::from_xml_element(child_node)?)),
                "clrMapOvr" => {
                    let clr_map_node = child_node.child_nodes.get(0).ok_or_else(|| {
                        MissingChildNodeError::new(child_node.name.clone(), "masterClrMapping|overrideClrMapping")
                    })?;
                    color_mapping_override = Some(drawingml::ColorMappingOverride::from_xml_element(
                        clr_map_node,
                    )?);
                }
                "transition" => transition = Some(Box::new(SlideTransition::from_xml_element(child_node)?)),
                "timing" => timing = Some(SlideTiming::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let common_slide_data =
            common_slide_data.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cSld"))?;

        Ok(Self {
            show,
            show_master_shapes,
            show_master_placeholder_animations,
            common_slide_data,
            color_mapping_override,
            transition,
            timing,
        })
    }
}

#[derive(Debug, Clone)]
pub struct BackgroundProperties {
    /// Specifies whether the background of the slide is of a shade to title background type. This
    /// kind of gradient fill is on the slide background and changes based on the placement of
    /// the slide title placeholder.
    ///
    /// Defaults to false
    pub shade_to_title: Option<bool>,
    pub fill: drawingml::FillProperties,
    pub effect: Option<drawingml::EffectProperties>,
}

impl BackgroundProperties {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let shade_to_title = match xml_node.attribute("shadeToTitle") {
            Some(val) => Some(parse_xml_bool(val)?),
            None => None,
        };

        let mut fill = None;
        let mut effect = None;

        for child_node in &xml_node.child_nodes {
            if drawingml::FillProperties::is_choice_member(child_node.local_name()) {
                fill = Some(drawingml::FillProperties::from_xml_element(child_node)?);
            } else if drawingml::EffectProperties::is_choice_member(child_node.local_name()) {
                effect = Some(drawingml::EffectProperties::from_xml_element(child_node)?);
            }
        }

        let fill = fill.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "EG_FillProperties"))?;

        Ok(Self {
            shade_to_title,
            fill,
            effect,
        })
    }
}

#[derive(Debug, Clone)]
pub enum BackgroundGroup {
    /// This element specifies visual effects used to render the slide background. This includes any fill, image, or effects
    /// that are to make up the background of the slide.
    Properties(BackgroundProperties),
    /// This element specifies the slide background is to use a fill style defined in the style matrix.
    /// The idx attribute refers to the index of a background fill style or fill style within the presentation's
    /// style matrix, defined by the fmtScheme element.
    /// A value of 0 or 1000 indicates no background, values 1-999 refer to the index of a fill style
    /// within the fillStyleLst element, and values 1001 and above refer to the index of a background fill style within
    /// the bgFillStyleLst element. The value 1001 corresponds to the first background fill style, 1002 to the second
    /// background fill style, and so on.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:bgRef idx="2">
    ///   <a:schemeClr val="bg2"/>
    /// </p:bgRef>
    /// ```
    ///
    /// The above code indicates a slide background with the style's second fill style using the second background color
    /// of the color scheme.
    ///
    /// ```xml
    /// <p:bgRef idx="1001">
    ///   <a:schemeClr val="bg2"/>
    /// </p:bgRef>
    /// ```
    ///
    /// The above code indicates a slide background with the style's first background fill style using the second
    /// background color of the color scheme.
    Reference(drawingml::StyleMatrixReference),
}

impl BackgroundGroup {
    pub fn is_choice_member(name: &str) -> bool {
        match name {
            "bgPr" | "bgRef" => true,
            _ => false,
        }
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        match xml_node.local_name() {
            "bgPr" => Ok(BackgroundGroup::Properties(BackgroundProperties::from_xml_element(
                xml_node,
            )?)),
            "bgRef" => Ok(BackgroundGroup::Reference(
                drawingml::StyleMatrixReference::from_xml_element(xml_node)?,
            )),
            _ => Err(NotGroupMemberError::new(xml_node.name.clone(), "EG_Background").into()),
        }
    }
}

#[derive(Debug, Clone)]
pub struct Background {
    /// Specifies that the background should be rendered using only black and white coloring.
    /// That is, the coloring information for the background should be converted to either black
    /// or white when rendering the picture.
    ///
    /// # Note
    ///
    /// No gray is to be used in rendering this background, only stark black and stark
    /// white.
    pub black_and_white_mode: Option<drawingml::BlackWhiteMode>, // white
    pub background: BackgroundGroup,
}

impl Background {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let black_and_white_mode = match xml_node.attribute("bwMode") {
            Some(val) => Some(val.parse()?),
            None => None,
        };

        let background_node = xml_node
            .child_nodes
            .get(0)
            .ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "EG_Background"))?;
        let background = BackgroundGroup::from_xml_element(background_node)?;

        Ok(Self {
            background,
            black_and_white_mode,
        })
    }
}

#[derive(Default, Debug, Clone)]
pub struct Placeholder {
    /// Specifies what content type a placeholder is intended to contain.
    pub placeholder_type: Option<PlaceholderType>,
    /// Specifies the orientation of a placeholder.
    pub orientation: Option<Direction>,
    /// Specifies the size of a placeholder.
    pub size: Option<PlaceholderSize>,
    /// Specifies the placeholder index. This is used when applying templates or changing
    /// layouts to match a placeholder on one template/master to another.
    pub index: Option<u32>,
    /// Specifies whether the corresponding placeholder should have a custom prompt or not.
    pub has_custom_prompt: Option<bool>,
}

impl Placeholder {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "type" => instance.placeholder_type = Some(value.parse()?),
                "orient" => instance.orientation = Some(value.parse()?),
                "sz" => instance.size = Some(value.parse()?),
                "idx" => instance.index = Some(value.parse()?),
                "hasCustomPrompt" => instance.has_custom_prompt = Some(parse_xml_bool(value)?),
                _ => (),
            }
        }

        Ok(instance)
    }
}

/// This element specifies non-visual properties for objects. These properties include multimedia content associated
/// with an object and properties indicating how the object is to be used or displayed in different contexts.
#[derive(Default, Debug, Clone)]
pub struct ApplicationNonVisualDrawingProps {
    /// Specifies whether the picture belongs to a photo album and should thus be included
    /// when editing a photo album within the generating application.
    pub is_photo: Option<bool>,
    /// Specifies if the corresponding object has been drawn by the user and should thus not be
    /// deleted. This allows for the flagging of slides that contain user drawn data.
    pub is_user_drawn: Option<bool>, // false
    /// This element specifies that the corresponding shape should be represented by the generating application as a
    /// placeholder. When a shape is considered a placeholder by the generating application it can have special
    /// properties to alert the user that they can enter content into the shape. Different placeholder types are allowed
    /// and can be specified by using the placeholder type attribute for this element.
    pub placeholder: Option<Placeholder>,
    pub media: Option<drawingml::Media>,
    pub customer_data_list: Option<CustomerDataList>,
}

impl ApplicationNonVisualDrawingProps {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "isPhoto" => instance.is_photo = Some(parse_xml_bool(value)?),
                "userDrawn" => instance.is_user_drawn = Some(parse_xml_bool(value)?),
                _ => (),
            }
        }

        for child_node in &xml_node.child_nodes {
            let local_name = child_node.local_name();
            if drawingml::Media::is_choice_member(local_name) {
                instance.media = Some(drawingml::Media::from_xml_element(child_node)?);
            } else {
                match child_node.local_name() {
                    "ph" => instance.placeholder = Some(Placeholder::from_xml_element(child_node)?),
                    "custDataLst" => {
                        instance.customer_data_list = Some(CustomerDataList::from_xml_element(child_node)?)
                    }
                    _ => (),
                }
            }
        }

        Ok(instance)
    }
}

#[derive(Debug, Clone)]
pub enum ShapeGroup {
    /// This element specifies the existence of a single shape. A shape can either be a preset or a custom geometry,
    /// defined using the DrawingML framework. In addition to a geometry each shape can have both visual and non-
    /// visual properties attached. Text and corresponding styling information can also be attached to a shape. This
    /// shape is specified along with all other shapes within either the shape tree or group shape elements.
    Shape(Box<Shape>),
    /// This element specifies a group shape that represents many shapes grouped together. This shape is to be treated
    /// just as if it were a regular shape but instead of being described by a single geometry it is made up of all the
    /// shape geometries encompassed within it. Within a group shape each of the shapes that make up the group are
    /// specified just as they normally would. The idea behind grouping elements however is that a single transform can
    /// apply to many shapes at the same time.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:grpSp>
    ///   <p:nvGrpSpPr>
    ///     <p:cNvPr id="10" name="Group 9"/>
    ///     <p:cNvGrpSpPr/>
    ///     <p:nvPr/>
    ///   </p:nvGrpSpPr>
    ///   <p:grpSpPr>
    ///     <a:xfrm>
    ///       <a:off x="838200" y="990600"/>
    ///       <a:ext cx="2426208" cy="978408"/>
    ///       <a:chOff x="838200" y="990600"/>
    ///       <a:chExt cx="2426208" cy="978408"/>
    ///     </a:xfrm>
    ///   </p:grpSpPr>
    ///   <p:sp>
    ///   ...
    ///   </p:sp>
    ///   <p:sp>
    ///   ...
    ///   </p:sp>
    ///   <p:sp>
    ///   ...
    ///   </p:sp>
    /// </p:grpSp>
    /// ```
    ///
    /// In the above example we see three shapes specified within a single group. These three shapes have their
    /// position and sizes specified just as they normally would within the shape tree.
    /// The generating application should apply the transformation after the bounding box for the group shape has been
    /// calculated.
    GroupShape(Box<GroupShape>),
    /// This element specifies the existence of a graphics frame. This frame contains a graphic that was generated by an
    /// external source and needs a container in which to be displayed on the slide surface.
    GraphicFrame(Box<GraphicalObjectFrame>),
    /// This element specifies a connection shape that is used to connect two sp elements.
    /// Once a connection is specified using a Connector, it is left to the generating application to determine the
    /// exact path the connector takes.
    /// That is the connector routing algorithm is left up to the generating application as the desired path might be
    /// different depending on the specific needs of the application.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:spTree>
    ///   ...
    ///   <p:sp>
    ///     <p:nvSpPr>
    ///       <p:cNvPr id="1" name="Rectangle 1"/>
    ///       <p:cNvSpPr/>
    ///       <p:nvPr/>
    ///     </p:nvSpPr>
    ///   ...
    ///   </p:sp>
    ///   <p:sp>
    ///     <p:nvSpPr>
    ///       <p:cNvPr id="2" name="Rectangle 2"/>
    ///       <p:cNvSpPr/>
    ///       <p:nvPr/>
    ///     </p:nvSpPr>
    ///     ...
    ///   </p:sp>
    ///   <p:cxnSp>
    ///     <p:nvCxnSpPr>
    ///       <p:cNvPr id="3" name="Elbow Connector 3"/>
    ///       <p:cNvCxnSpPr>
    ///         <a:stCxn id="1" idx="3"/>
    ///         <a:endCxn id="2" idx="1"/>
    ///       </p:cNvCxnSpPr>
    ///       <p:nvPr/>
    ///     </p:nvCxnSpPr>
    ///     ...
    ///   </p:cxnSp>
    /// </p:spTree>
    /// ```
    Connector(Box<Connector>),
    /// This element specifies the existence of a picture object within the document.
    ///
    /// # Xml example
    ///
    /// Consider the following PresentationML that specifies the existence of a picture within a document.
    /// This picture can have non-visual properties, a picture fill as well as shape properties attached to it.
    ///
    /// ```xml
    /// <p:pic>
    ///   <p:nvPicPr>
    ///     <p:cNvPr id="4" name="lake.JPG" descr="Picture of a Lake" />
    ///     <p:cNvPicPr>
    ///       <a:picLocks noChangeAspect="1"/>
    ///     </p:cNvPicPr>
    ///     <p:nvPr/>
    ///   </p:nvPicPr>
    ///   <p:blipFill>
    ///   ...
    ///   </p:blipFill>
    ///   <p:spPr>
    ///   ...
    ///   </p:spPr>
    /// </p:pic>
    /// ```
    Picture(Box<Picture>),
    /// This element specifies a reference to XML content in a format not defined by ECMA-376.
    ///
    /// The relationship type of the explicit relationship specified by this element shall be
    /// http://purl.oclc.org/ooxml/officeDocument/relationships/customXml and have a TargetMode attribute value of
    /// Internal. If an application cannot process content of the content type specified by the targeted part, then it
    /// should continue to process the file.
    /// If possible, it should also provide some indication that unknown content was not imported.
    ///
    /// # Note
    ///
    /// This part allows the native use of other commonly used interchange formats, such as:
    /// * [MathML](http://www.w3.org/TR/MathML2/)
    /// * [SMIL](http://www.w3.org/TR/REC-smil/)
    /// * [SVG](http://www.w3.org/TR/SVG11/)
    ///
    /// For better interoperability, only standard XML formats should be used.
    ContentPart(RelationshipId),
}

impl ShapeGroup {
    pub fn is_choice_member<T>(name: T) -> bool
    where
        T: AsRef<str>,
    {
        match name.as_ref() {
            "sp" | "grpSp" | "graphicFrame" | "cxnSp" | "pic" | "contentPart" => true,
            _ => false,
        }
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        match xml_node.local_name() {
            "sp" => Ok(ShapeGroup::Shape(Box::new(Shape::from_xml_element(xml_node)?))),
            "grpSp" => Ok(ShapeGroup::GroupShape(Box::new(GroupShape::from_xml_element(
                xml_node,
            )?))),
            "graphicFrame" => Ok(ShapeGroup::GraphicFrame(Box::new(
                GraphicalObjectFrame::from_xml_element(xml_node)?,
            ))),
            "cxnSp" => Ok(ShapeGroup::Connector(Box::new(Connector::from_xml_element(xml_node)?))),
            "pic" => Ok(ShapeGroup::Picture(Box::new(Picture::from_xml_element(xml_node)?))),
            "contentPart" => {
                let attr = xml_node
                    .attribute("r:id")
                    .ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "r:id"))?;
                Ok(ShapeGroup::ContentPart(attr.clone()))
            }
            _ => Err(Box::new(NotGroupMemberError::new(
                xml_node.name.clone(),
                "EG_ShapeGroup",
            ))),
        }
    }
}

#[derive(Debug, Clone)]
pub struct Shape {
    /// Specifies that the shape fill should be set to that of the slide background surface.
    ///
    /// # Note
    ///
    /// This attribute does not set the fill of the shape to be transparent but instead sets it
    /// to be filled with the portion of the slide background that is directly behind it.
    pub use_bg_fill: Option<bool>,
    /// This element specifies all non-visual properties for a shape. This element is a container for the non-visual
    /// identification properties, shape properties and application properties that are to be associated with a shape.
    /// This allows for additional information that does not affect the appearance of the shape to be stored.
    pub non_visual_props: Box<ShapeNonVisual>,
    /// This element specifies the visual shape properties that can be applied to a shape. These properties include the
    /// shape fill, outline, geometry, effects, and 3D orientation.
    pub shape_props: Box<drawingml::ShapeProperties>,
    /// This element specifies the style information for a shape. This is used to define a shape's appearance in terms of
    /// the preset styles defined by the style matrix for the theme.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:style>
    ///   <a:lnRef idx="3">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:lnRef>
    ///   <a:fillRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:fillRef>
    ///   <a:effectRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:effectRef>
    ///   <a:fontRef idx="minor">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:fontRef>
    /// </p:style>
    /// ```
    ///
    /// The parent shape of the above code is to have an outline that uses the third line style defined by the theme, use
    /// the first fill defined by the scheme, and be rendered with the first effect defined by the theme. Text inside the
    /// shape is to use the minor font defined by the theme.
    pub shape_style: Option<Box<drawingml::ShapeStyle>>,
    /// This element specifies the existence of text to be contained within the corresponding shape. All visible text and
    /// visible text related properties are contained within this element. There can be multiple paragraphs and within
    /// paragraphs multiple runs of text.
    pub text_body: Option<drawingml::TextBody>,
}

impl Shape {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let use_bg_fill = match xml_node.attribute("useBgFill") {
            Some(val) => Some(parse_xml_bool(val)?),
            None => None,
        };

        let mut non_visual_props = None;
        let mut shape_props = None;
        let mut shape_style = None;
        let mut text_body = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "nvSpPr" => non_visual_props = Some(Box::new(ShapeNonVisual::from_xml_element(child_node)?)),
                "spPr" => {
                    shape_props = Some(Box::new(drawingml::ShapeProperties::from_xml_element(
                        child_node,
                    )?))
                }
                "style" => {
                    shape_style = Some(Box::new(drawingml::ShapeStyle::from_xml_element(
                        child_node,
                    )?))
                }
                "txBody" => text_body = Some(drawingml::TextBody::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let non_visual_props =
            non_visual_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvSpPr"))?;
        let shape_props = shape_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "spPr"))?;

        Ok(Self {
            use_bg_fill,
            non_visual_props,
            shape_props,
            shape_style,
            text_body,
        })
    }
}

#[derive(Debug, Clone)]
pub struct ShapeNonVisual {
    pub drawing_props: Box<drawingml::NonVisualDrawingProps>,
    /// This element specifies the non-visual drawing properties for a shape. These properties are to be used by the
    /// generating application to determine how the shape should be dealt with.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:sp>
    ///   <p:nvSpPr>
    ///     <p:cNvPr id="2" name="Rectangle 1"/>
    ///     <p:cNvSpPr>
    ///       <a:spLocks noGrp="1"/>
    ///     </p:cNvSpPr>
    ///   </p:nvSpPr>
    ///   ...
    /// </p:sp>
    /// ```
    ///
    /// This shape lock is stored within the non-visual drawing properties for this shape.
    pub shape_drawing_props: drawingml::NonVisualDrawingShapeProps,
    pub app_props: ApplicationNonVisualDrawingProps,
}

impl ShapeNonVisual {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut drawing_props = None;
        let mut shape_drawing_props = None;
        let mut app_props = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cNvPr" => {
                    drawing_props = Some(Box::new(
                        drawingml::NonVisualDrawingProps::from_xml_element(child_node)?,
                    ))
                }
                "cNvSpPr" => {
                    shape_drawing_props =
                        Some(drawingml::NonVisualDrawingShapeProps::from_xml_element(child_node)?)
                }
                "nvPr" => app_props = Some(ApplicationNonVisualDrawingProps::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let drawing_props = drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPr"))?;
        let shape_drawing_props =
            shape_drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvSpPr"))?;
        let app_props = app_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPr"))?;

        Ok(Self {
            drawing_props,
            shape_drawing_props,
            app_props,
        })
    }
}

#[derive(Debug, Clone)]
pub struct GroupShape {
    /// This element specifies all non-visual properties for a group shape. This element is a container for the
    /// non-visual identification properties, shape properties and application properties that are to be associated
    /// with a group shape.
    /// This allows for additional information that does not affect the appearance of the group shape to be stored.
    pub non_visual_props: Box<GroupShapeNonVisual>,
    /// This element specifies the properties that are to be common across all of the shapes within the corresponding
    /// group. If there are any conflicting properties within the group shape properties and the individual shape
    /// properties then the individual shape properties should take precedence.
    pub group_shape_props: drawingml::GroupShapeProperties,
    pub shape_array: Vec<ShapeGroup>,
}

impl GroupShape {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut non_visual_props = None;
        let mut group_shape_props = None;
        let mut shape_array = Vec::new();

        for child_node in &xml_node.child_nodes {
            let child_local_name = child_node.local_name();
            if ShapeGroup::is_choice_member(child_local_name) {
                shape_array.push(ShapeGroup::from_xml_element(child_node)?);
            } else {
                match child_local_name {
                    "nvGrpSpPr" => {
                        non_visual_props = Some(Box::new(GroupShapeNonVisual::from_xml_element(child_node)?))
                    }
                    "grpSpPr" => {
                        group_shape_props = Some(drawingml::GroupShapeProperties::from_xml_element(
                            child_node,
                        )?)
                    }
                    _ => (),
                }
            }
        }

        let non_visual_props =
            non_visual_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvGrpSpPr"))?;
        let group_shape_props =
            group_shape_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "grpSpPr"))?;

        Ok(Self {
            non_visual_props,
            group_shape_props,
            shape_array,
        })
    }
}

#[derive(Debug, Clone)]
pub struct GroupShapeNonVisual {
    pub drawing_props: Box<drawingml::NonVisualDrawingProps>,
    /// This element specifies the non-visual drawing properties for a group shape. These non-visual properties are
    /// properties that the generating application would utilize when rendering the slide surface.
    pub group_drawing_props: drawingml::NonVisualGroupDrawingShapeProps,
    pub app_props: ApplicationNonVisualDrawingProps,
}

impl GroupShapeNonVisual {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut drawing_props = None;
        let mut group_drawing_props = None;
        let mut app_props = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cNvPr" => {
                    drawing_props = Some(Box::new(
                        drawingml::NonVisualDrawingProps::from_xml_element(child_node)?,
                    ))
                }
                "cNvGrpSpPr" => {
                    group_drawing_props =
                        Some(drawingml::NonVisualGroupDrawingShapeProps::from_xml_element(child_node)?)
                }
                "nvPr" => app_props = Some(ApplicationNonVisualDrawingProps::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let drawing_props = drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPr"))?;
        let group_drawing_props =
            group_drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvGrpSpPr"))?;
        let app_props = app_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPr"))?;
        Ok(Self {
            drawing_props,
            group_drawing_props,
            app_props,
        })
    }
}

#[derive(Debug, Clone)]
pub struct GraphicalObjectFrame {
    /// Specifies how the graphical object should be rendered, using color, black or white,
    /// or grayscale.
    ///
    /// # Note
    ///
    /// This does not mean that the graphical object itself is stored with only black
    /// and white or grayscale information. This attribute instead sets the rendering mode
    /// that the graphical object uses.
    pub black_white_mode: Option<drawingml::BlackWhiteMode>,
    /// This element specifies all non-visual properties for a graphic frame. This element is a container for the
    /// non-visual identification properties, shape properties and application properties that are to be associated
    /// with a graphic frame.
    /// This allows for additional information that does not affect the appearance of the graphic frame to be stored.
    pub non_visual_props: Box<GraphicalObjectFrameNonVisual>,
    /// This element specifies the transform to be applied to the corresponding graphic frame. This transformation is
    /// applied to the graphic frame just as it would be for a shape or group shape.
    pub transform: Box<drawingml::Transform2D>,
    pub graphic: drawingml::GraphicalObject,
}

impl GraphicalObjectFrame {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let black_white_mode = match xml_node.attribute("bwMode") {
            Some(attr) => Some(attr.parse()?),
            None => None,
        };

        let mut non_visual_props = None;
        let mut transform = None;
        let mut graphic = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "nvGraphicFramePr" => {
                    non_visual_props = Some(Box::new(GraphicalObjectFrameNonVisual::from_xml_element(child_node)?))
                }
                "xfrm" => {
                    transform = Some(Box::new(drawingml::Transform2D::from_xml_element(
                        child_node,
                    )?))
                }
                "graphic" => {
                    graphic = Some(drawingml::GraphicalObject::from_xml_element(
                        child_node,
                    )?)
                }
                _ => (),
            }
        }

        let non_visual_props =
            non_visual_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvGraphicFramePr"))?;
        let transform = transform.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "xfrm"))?;
        let graphic = graphic.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "graphic"))?;

        Ok(Self {
            black_white_mode,
            non_visual_props,
            transform,
            graphic,
        })
    }
}

#[derive(Debug, Clone)]
pub struct GraphicalObjectFrameNonVisual {
    pub drawing_props: Box<drawingml::NonVisualDrawingProps>,
    /// This element specifies the non-visual drawing properties for a graphic frame. These non-visual properties are
    /// properties that the generating application would utilize when rendering the slide surface.
    pub graphic_frame_props: drawingml::NonVisualGraphicFrameProperties,
    pub app_props: ApplicationNonVisualDrawingProps,
}

impl GraphicalObjectFrameNonVisual {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut drawing_props = None;
        let mut graphic_frame_props = None;
        let mut app_props = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cNvPr" => {
                    drawing_props = Some(Box::new(
                        drawingml::NonVisualDrawingProps::from_xml_element(child_node)?,
                    ))
                }
                "cNvGraphicFramePr" => {
                    graphic_frame_props =
                        Some(drawingml::NonVisualGraphicFrameProperties::from_xml_element(child_node)?)
                }
                "nvPr" => app_props = Some(ApplicationNonVisualDrawingProps::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let drawing_props = drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPr"))?;
        let graphic_frame_props = graphic_frame_props
            .ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvGraphicFramePr"))?;
        let app_props = app_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPr"))?;

        Ok(Self {
            drawing_props,
            graphic_frame_props,
            app_props,
        })
    }
}

#[derive(Debug, Clone)]
pub struct Connector {
    /// This element specifies all non-visual properties for a connection shape. This element is a container for the non-
    /// visual identification properties, shape properties and application properties that are to be associated with a
    /// connection shape. This allows for additional information that does not affect the appearance of the connection
    /// shape to be stored.
    pub non_visual_props: Box<ConnectorNonVisual>,
    /// This element specifies the visual shape properties that can be applied to a shape. These properties include the
    /// shape fill, outline, geometry, effects, and 3D orientation.
    pub shape_props: Box<drawingml::ShapeProperties>,
    /// This element specifies the style information for a shape. This is used to define a shape's appearance in terms of
    /// the preset styles defined by the style matrix for the theme.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:style>
    ///   <a:lnRef idx="3">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:lnRef>
    ///   <a:fillRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:fillRef>
    ///   <a:effectRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:effectRef>
    ///   <a:fontRef idx="minor">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:fontRef>
    /// </p:style>
    /// ```
    ///
    /// The parent shape of the above code is to have an outline that uses the third line style defined by the theme, use
    /// the first fill defined by the scheme, and be rendered with the first effect defined by the theme. Text inside the
    /// shape is to use the minor font defined by the theme.
    pub shape_style: Option<Box<drawingml::ShapeStyle>>,
}

impl Connector {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut non_visual_props = None;
        let mut shape_props = None;
        let mut shape_style = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "nvCxnSpPr" => non_visual_props = Some(Box::new(ConnectorNonVisual::from_xml_element(child_node)?)),
                "spPr" => {
                    shape_props = Some(Box::new(drawingml::ShapeProperties::from_xml_element(
                        child_node,
                    )?))
                }
                "style" => {
                    shape_style = Some(Box::new(drawingml::ShapeStyle::from_xml_element(
                        child_node,
                    )?))
                }
                _ => (),
            }
        }

        let non_visual_props =
            non_visual_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvCxnSpPr"))?;
        let shape_props = shape_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvCxnSpPr"))?;

        Ok(Self {
            non_visual_props,
            shape_props,
            shape_style,
        })
    }
}

#[derive(Debug, Clone)]
pub struct ConnectorNonVisual {
    pub drawing_props: Box<drawingml::NonVisualDrawingProps>,
    /// This element specifies the non-visual drawing properties specific to a connector shape. This includes
    /// information specifying the shapes to which the connector shape is connected.
    pub connector_props: drawingml::NonVisualConnectorProperties,
    pub app_props: ApplicationNonVisualDrawingProps,
}

impl ConnectorNonVisual {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut drawing_props = None;
        let mut connector_props = None;
        let mut app_props = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cNvPr" => {
                    drawing_props = Some(Box::new(
                        drawingml::NonVisualDrawingProps::from_xml_element(child_node)?,
                    ))
                }
                "cNvCxnSpPr" => {
                    connector_props =
                        Some(drawingml::NonVisualConnectorProperties::from_xml_element(child_node)?)
                }
                "nvPr" => app_props = Some(ApplicationNonVisualDrawingProps::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let drawing_props = drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPr"))?;
        let connector_props =
            connector_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvCxnSpPr"))?;
        let app_props = app_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPr"))?;

        Ok(Self {
            drawing_props,
            connector_props,
            app_props,
        })
    }
}

#[derive(Debug, Clone)]
pub struct Picture {
    /// This element specifies all non-visual properties for a picture. This element is a container for the non-visual
    /// identification properties, shape properties and application properties that are to be associated with a picture.
    /// This allows for additional information that does not affect the appearance of the picture to be stored.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:pic>
    ///   ...
    ///   <p:nvPicPr>
    ///   ...
    ///   </p:nvPicPr>
    ///   ...
    /// </p:pic>
    /// ```
    pub non_visual_props: Box<PictureNonVisual>,
    pub blip_fill: Box<drawingml::BlipFillProperties>,
    pub shape_props: Box<drawingml::ShapeProperties>,
    /// This element specifies the style information for a shape. This is used to define a shape's appearance in terms of
    /// the preset styles defined by the style matrix for the theme.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:style>
    ///   <a:lnRef idx="3">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:lnRef>
    ///   <a:fillRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:fillRef>
    ///   <a:effectRef idx="1">
    ///     <a:schemeClr val="accent3"/>
    ///   </a:effectRef>
    ///   <a:fontRef idx="minor">
    ///     <a:schemeClr val="lt1"/>
    ///   </a:fontRef>
    /// </p:style>
    /// ```
    ///
    /// The parent shape of the above code is to have an outline that uses the third line style defined by the theme, use
    /// the first fill defined by the scheme, and be rendered with the first effect defined by the theme. Text inside the
    /// shape is to use the minor font defined by the theme.
    pub shape_style: Option<Box<drawingml::ShapeStyle>>,
}

impl Picture {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut non_visual_props = None;
        let mut blip_fill = None;
        let mut shape_props = None;
        let mut shape_style = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "nvPicPr" => non_visual_props = Some(Box::new(PictureNonVisual::from_xml_element(child_node)?)),
                "blipFill" => {
                    blip_fill = Some(Box::new(
                        drawingml::BlipFillProperties::from_xml_element(child_node)?,
                    ))
                }
                "spPr" => {
                    shape_props = Some(Box::new(drawingml::ShapeProperties::from_xml_element(
                        child_node,
                    )?))
                }
                "style" => {
                    shape_style = Some(Box::new(drawingml::ShapeStyle::from_xml_element(
                        child_node,
                    )?))
                }
                _ => (),
            }
        }

        let non_visual_props =
            non_visual_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPicPr"))?;
        let blip_fill = blip_fill.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "blipFill"))?;
        let shape_props = shape_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "spPr"))?;

        Ok(Self {
            non_visual_props,
            blip_fill,
            shape_props,
            shape_style,
        })
    }
}

#[derive(Debug, Clone)]
pub struct PictureNonVisual {
    pub drawing_props: Box<drawingml::NonVisualDrawingProps>,
    /// This element specifies the non-visual properties for the picture canvas. These properties are to be used by the
    /// generating application to determine how certain properties are to be changed for the picture object in question.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:pic>
    ///   ...
    ///   <p:nvPicPr>
    ///     <p:cNvPr id="4" name="Lilly_by_Lisher.jpg"/>
    ///     <p:cNvPicPr>
    ///       <a:picLocks noChangeAspect="1"/>
    ///     </p:cNvPicPr>
    ///     <p:nvPr/>
    ///   </p:nvPicPr>
    ///   ...
    /// </p:pic>
    /// ```
    pub picture_props: drawingml::NonVisualPictureProperties,
    pub app_props: ApplicationNonVisualDrawingProps,
}

impl PictureNonVisual {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut drawing_props = None;
        let mut picture_props = None;
        let mut app_props = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "cNvPr" => {
                    drawing_props = Some(Box::new(
                        drawingml::NonVisualDrawingProps::from_xml_element(child_node)?,
                    ))
                }
                "cNvPicPr" => {
                    picture_props =
                        Some(drawingml::NonVisualPictureProperties::from_xml_element(child_node)?)
                }
                "nvPr" => app_props = Some(ApplicationNonVisualDrawingProps::from_xml_element(child_node)?),
                _ => (),
            }
        }

        let drawing_props = drawing_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPr"))?;
        let picture_props =
            picture_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "cNvPicPr"))?;
        let app_props = app_props.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "nvPr"))?;

        Ok(Self {
            drawing_props,
            picture_props,
            app_props,
        })
    }
}

/// This element specifies a container for slide information that is relevant to all of the slide types.
/// All slides share a common set of properties that is independent of the slide type; the description of these
/// properties for any particular slide is stored within the slide's common_slide_data container.
/// Slide data specific to the slide type indicated by the parent element is stored elsewhere.
///
/// # Note
///
/// The actual data in CommonSlideData describe only the particular parent slide; it is only the kind of information
/// stored that is common across all slides.
///
/// # Xml example
///
/// ```xml
/// <p:sld>
///   <p:cSld>
///     <p:spTree>
///     ...
///     </p:spTree>
///   </p:cSld>
///   ...
/// </p:sld>
/// ```
#[derive(Debug, Clone)]
pub struct CommonSlideData {
    /// Specifies the slide name property that is used to further identify this unique configuration
    /// of common slide data. This might be used to aid in distinguishing different slide layouts or
    /// various other slide types.
    pub name: Option<String>,
    /// This element specifies the background appearance information for a slide. The slide background covers the
    /// entire slide and is visible where no objects exist and as the background for transparent objects.
    pub background: Option<Box<Background>>,
    /// This element specifies all shape-based objects, either grouped or not, that can be referenced on a given slide. As
    /// most objects within a slide are shapes, this represents the majority of content within a slide. Text and effects are
    /// attached to shapes that are contained within the shape_tree element.
    ///
    /// Each shape-based object within the shape tree, whether grouped or not, shall represent one unique level of z-
    /// ordering on the slide. The z-order for each shape-based object shall be determined by the lexical ordering of
    /// each shape-based object within the shape tree: the first shape-based object shall have the lowest z-order, while
    /// the last shape-based object shall have the highest z-order.
    ///
    /// The z-ordering of shape-based objects within the shape tree shall also determine the navigation (tab) order of
    /// the shape-based objects: the shape-based object with the lowest z-order (the first shape in lexical order) shall be
    /// first in navigation order, with objects being navigated in ascending z-order.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:sld>
    ///   <p:cSld>
    ///     <p:spTree>
    ///       <p:nvGrpSpPr>
    ///       ...
    ///       </p:nvGrpSpPr>
    ///       <p:grpSpPr>
    ///       ...
    ///       </p:grpSpPr>
    ///       <p:sp>
    ///       ...
    ///       </p:sp>
    ///     </p:spTree>
    ///   </p:cSld>
    ///   ...
    /// </p:sld>
    /// ```
    pub shape_tree: Box<GroupShape>,
    pub customer_data_list: Option<CustomerDataList>,
    /// This element specifies a list of embedded controls for the corresponding slide. Custom embedded controls can
    /// be embedded on slides.
    pub control_list: Option<Vec<Control>>,
}

impl CommonSlideData {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let name = xml_node.attribute("name").cloned();
        let mut background = None;
        let mut shape_tree = None;
        let mut customer_data_list = None;
        let mut control_list = None;

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "bg" => background = Some(Box::new(Background::from_xml_element(child_node)?)),
                "spTree" => shape_tree = Some(Box::new(GroupShape::from_xml_element(child_node)?)),
                "custDataList" => customer_data_list = Some(CustomerDataList::from_xml_element(child_node)?),
                "controls" => {
                    let mut vec = Vec::new();
                    for control_node in &child_node.child_nodes {
                        vec.push(Control::from_xml_element(control_node)?);
                    }

                    control_list = Some(vec);
                }
                _ => (),
            }
        }

        let shape_tree =
            shape_tree.ok_or_else(|| XmlError::from(MissingChildNodeError::new(xml_node.name.clone(), "spTree")))?;

        Ok(Self {
            name,
            background,
            shape_tree,
            customer_data_list,
            control_list,
        })
    }
}

#[derive(Default, Debug, Clone)]
pub struct SlideMasterTextStyles {
    /// This element specifies the text formatting style for the title text within a master slide. This formatting is used on
    /// all title text within related presentation slides. The text formatting is specified by utilizing the DrawingML
    /// framework just as within a regular presentation slide. Within a title style there can be many different style types
    /// defined as there are different kinds of text stored within a slide title.
    pub title_styles: Option<Box<drawingml::TextListStyle>>,
    /// This element specifies the text formatting style for all body text within a master slide.
    /// This formatting is used on all body text within presentation slides related to this master.
    /// The text formatting is specified by utilizing the DrawingML framework just as within a regular
    /// presentation slide.
    /// Within the bodyStyle element there can be many different style types defined as there are different kinds of
    /// text stored within the body of a slide.
    pub body_styles: Option<Box<drawingml::TextListStyle>>,
    /// This element specifies the text formatting style for the all other text within a master slide. This formatting is
    /// used on all text not covered by the title_styles or body_styles elements within related presentation slides. The text
    /// formatting is specified by utilizing the DrawingML framework just as within a regular presentation slide. Within
    /// the otherStyle element there can be many different style types defined as there are different kinds of text
    /// stored within a slide.
    ///
    /// # Note
    ///
    /// The other_styles element is to be used for specifying the text formatting of text within a slide shape but
    /// not within a text box. Text box styling is handled from within the body_styles element.
    pub other_styles: Option<Box<drawingml::TextListStyle>>,
}

impl SlideMasterTextStyles {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "titleStyle" => {
                    instance.title_styles = Some(Box::new(drawingml::TextListStyle::from_xml_element(
                        child_node,
                    )?))
                }
                "bodyStyle" => {
                    instance.body_styles = Some(Box::new(drawingml::TextListStyle::from_xml_element(
                        child_node,
                    )?))
                }
                "otherStyle" => {
                    instance.other_styles = Some(Box::new(drawingml::TextListStyle::from_xml_element(
                        child_node,
                    )?))
                }
                _ => (),
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct OrientationTransition {
    /// This attribute specifies a horizontal or vertical transition.
    ///
    /// Defaults to Direction::Horizontal
    pub direction: Option<Direction>,
}

impl OrientationTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let direction = match xml_node.attribute("dir") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { direction })
    }
}

#[derive(Default, Debug, Clone)]
pub struct EightDirectionTransition {
    /// This attribute specifies if the direction of the transition.
    ///
    /// Defaults to TransitionEightDirectionType::Left
    pub direction: Option<TransitionEightDirectionType>,
}

impl EightDirectionTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let direction = match xml_node.attribute("dir") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { direction })
    }
}

#[derive(Default, Debug, Clone)]
pub struct OptionalBlackTransition {
    /// This attribute specifies if the transition starts from a black screen (and then transition the
    /// new slide over black).
    ///
    /// Defaults to false
    pub through_black: Option<bool>,
}

impl OptionalBlackTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let through_black = match xml_node.attribute("thruBlk") {
            Some(value) => Some(parse_xml_bool(value)?),
            None => None,
        };

        Ok(Self { through_black })
    }
}

#[derive(Default, Debug, Clone)]
pub struct SideDirectionTransition {
    /// This attribute specifies the direction of the slide transition.
    ///
    /// Defaults to TransitionSideDirectionType::Left
    pub direction: Option<TransitionSideDirectionType>,
}

impl SideDirectionTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let direction = match xml_node.attribute("dir") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { direction })
    }
}

#[derive(Default, Debug, Clone)]
pub struct SplitTransition {
    /// This attribute specifies the orientation of a "split" slide transition.
    ///
    /// Defaults to Direction::Horizontal
    pub orientation: Option<Direction>,
    /// This attribute specifies the direction of a "split" slide transition.
    ///
    /// Defaults to TransitionInOutDirectionType::Out
    pub direction: Option<TransitionInOutDirectionType>,
}

impl SplitTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "orient" => instance.orientation = Some(value.parse()?),
                "dir" => instance.direction = Some(value.parse()?),
                _ => (),
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct CornerDirectionTransition {
    /// This attribute specifies if the direction of the transition.
    ///
    /// Defaults to TransitionCornerDirectionType::LeftUp
    pub direction: Option<TransitionCornerDirectionType>,
}

impl CornerDirectionTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let direction = match xml_node.attribute("dir") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { direction })
    }
}

#[derive(Default, Debug, Clone)]
pub struct WheelTransition {
    /// This attributes specifies the number of spokes ("pie pieces") in the wheel
    ///
    /// Defaults to 4
    pub spokes: Option<u32>,
}

impl WheelTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let spokes = match xml_node.attribute("spokes") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { spokes })
    }
}

#[derive(Default, Debug, Clone)]
pub struct InOutTransition {
    /// This attribute specifies the direction of an "in/out" slide transition.
    ///
    /// Defaults to TransitionInOutDirectionType::Out
    pub direction: Option<TransitionInOutDirectionType>,
}

impl InOutTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let direction = match xml_node.attribute("dir") {
            Some(value) => Some(value.parse()?),
            None => None,
        };

        Ok(Self { direction })
    }
}

#[derive(Debug, Clone)]
pub enum SlideTransitionGroup {
    /// This element describes the blinds slide transition effect, which uses a set of horizontal or vertical bars and wipes
    /// them either left-to-right or top-to-bottom, respectively, until the new slide is fully shown. The rendering of this
    /// transition depends upon the attributes specified.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:blinds dir="horz"/>
    /// </p:transition>
    /// ```
    Blinds(OrientationTransition),
    /// This element describes the checker slide transition effect, which uses a set of horizontal or vertical
    /// checkerboard squares and wipes them either left-to-right or top-to-bottom, respectively, until the new slide is
    /// fully shown. The rendering of this transition depends upon the attributes specified.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:checker dir="horz"/>
    /// </p:transition>
    /// ```
    Checker(OrientationTransition),
    /// This element describes the circle slide transition effect, which uses a circle pattern centered on the slide that
    /// increases in size until the new slide is fully shown. The rendering of this transition has been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:circle/>
    /// </p:transition>
    /// ```
    Circle,
    /// This element describes the dissolve slide transition effect, which uses a set of randomly placed squares on the
    /// slide that continue to be added to until the new slide is fully shown. The rendering of this transition has been
    /// shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:dissolve/>
    /// </p:transition>
    /// ```
    Dissolve,
    /// This element describes the comb slide transition effect, which uses a set of horizontal or vertical bars and wipes
    /// them from one end of the slide to the other until the new slide is fully shown. The rendering of this transition
    /// depends upon the attributes specified which have been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:comb dir="horz"/>
    /// </p:transition>
    /// ```
    Comb(OrientationTransition),
    /// This element describes the cover slide transition effect, which moves the new slide in from an off-screen
    /// location, continually covering more of the previous slide until the new slide is fully shown. The rendering of this
    /// transition depends upon the attributes specified which have been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:cover dir="d"/>
    /// </p:transition>
    /// ```
    Cover(EightDirectionTransition),
    /// This element describes the cut slide transition effect, which simply replaces the previous slide with the new slide
    /// instantaneously. No animation is used, but an option exists to cut to a black screen before showing the new
    /// slide. The rendering of this transition depends upon the attributes specified which have been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:cut thruBlk="0"/>
    /// </p:transition>
    /// ```
    Cut(OptionalBlackTransition),
    /// This element describes the diamond slide transition effect, which uses a diamond pattern centered on the slide
    /// that increases in size until the new slide is fully shown. The rendering of this transition has been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:diamond/>
    /// </p:transition>
    /// ```
    Diamond,
    /// This element describes the fade slide transition effect, which smoothly fades the previous slide either directly to
    /// the new slide or first to a black screen and then to the new slide. The rendering of this transition depends upon
    /// the attributes specified which have been shown below.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:fade thruBlk="0"/>
    /// </p:transition>
    /// ```
    Fade(OptionalBlackTransition),
    /// This element describes the newsflash slide transition effect, which grows and spins the new slide counterclockwise
    /// into place over the previous slide. The rendering of this transition has been shown below.
    ///
    /// # Xml example
    ///
    /// Consider the following case in which the “newsflash” slide transition is applied to a slide, along with a
    /// set of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:newsflash/>
    /// </p:transition>
    /// ```
    Newsflash,
    /// This element describes the plus slide transition effect, which uses a plus pattern centered on the slide that
    /// increases in size until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following case in which the “plus” slide transition is applied to a slide, along with a set of
    /// attributes
    /// ```xml
    /// <p:transition>
    ///   <p:plus/>
    /// </p:transition>
    /// ```
    Plus,
    /// This element describes the pull slide transition effect, which moves the previous slide to an off-screen location,
    /// continually revealing more of the new slide until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “pull” slide transition is applied to a slide, along with a set of
    /// attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:pull dir="d"/>
    /// </p:transition>
    /// ```
    Pull(EightDirectionTransition),
    /// This element describes the push slide transition effect, which moves the new slide in from an off-screen
    /// location, continually pushing the previous slide to an opposite off-screen location until the new slide is fully
    /// shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “push” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:push dir="d"/>
    /// </p:transition>
    /// ```
    Push(SideDirectionTransition),
    /// This element describes the random slide transition effect, which chooses a random transition from the set
    /// available in the rendering application. This transition thus can be different each time it is used.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:random/>
    /// </p:transition>
    /// ```
    Random,
    /// This element describes the randomBar slide transition effect, which uses a set of randomly placed horizontal or
    /// vertical bars on the slide that continue to be added to until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “randomBar” slide transition is applied to a slide, along with
    /// a set of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:randomBar dir="horz"/>
    /// </p:transition>
    /// ```
    RandomBar(OrientationTransition),
    /// This element describes the split slide transition effect, which reveals the new slide directly on top of the
    /// previous one by wiping either horizontal or vertical from the outside in, or from the inside out, until the new
    /// slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “split” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:split orient="horz" dir="in"/>
    /// </p:transition>
    /// ```
    Split(SplitTransition),
    /// This element describes the strips slide transition effect, which uses a set of bars that are arranged in a staggered
    /// fashion and wipes them across the screen until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “strips” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:strips dir="ld"/>
    /// </p:transition>
    /// ```
    Strips(CornerDirectionTransition),
    /// This element describes the wedge slide transition effect, which uses two radial edges that wipe from top to
    /// bottom in opposite directions until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following case in which the “wedge” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:wedge/>
    /// </p:transition>
    /// ```
    Wedge,
    /// This element describes the wheel slide transition effect, which uses a set of radial edges and wipes them in the
    /// clockwise direction until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “wheel” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:wheel spokes="1"/>
    /// </p:transition>
    /// ```
    Wheel(WheelTransition),
    /// This element describes the wipe slide transition effect, which wipes the new slide over the previous slide from
    /// one edge of the screen to the opposite until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “wipe” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:wipe dir="d"/>
    /// </p:transition>
    /// ```
    Wipe(SideDirectionTransition),
    /// This element describes the zoom slide transition effect, which uses a box pattern centered on the slide that
    /// increases in size until the new slide is fully shown.
    ///
    /// # Xml example
    ///
    /// Consider the following cases in which the “zoom” slide transition is applied to a slide, along with a set
    /// of attributes.
    /// ```xml
    /// <p:transition>
    ///   <p:zoom dir="in"/>
    /// </p:transition>
    /// ```
    Zoom(InOutTransition),
}

impl SlideTransitionGroup {
    pub fn is_choice_member<T>(name: T) -> bool
    where
        T: AsRef<str>,
    {
        match name.as_ref() {
            "blinds" | "checker" | "circle" | "dissolve" | "comb" | "cover" | "cut" | "diamond" | "fade"
            | "newsflash" | "plus" | "pull" | "push" | "random" | "randomBar" | "split" | "strips" | "wedge"
            | "wheel" | "wipe" | "zoom" => true,
            _ => false,
        }
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        match xml_node.local_name() {
            "blinds" => Ok(SlideTransitionGroup::Blinds(OrientationTransition::from_xml_element(
                xml_node,
            )?)),
            "checker" => Ok(SlideTransitionGroup::Checker(OrientationTransition::from_xml_element(
                xml_node,
            )?)),
            "circle" => Ok(SlideTransitionGroup::Circle),
            "dissolve" => Ok(SlideTransitionGroup::Dissolve),
            "comb" => Ok(SlideTransitionGroup::Comb(OrientationTransition::from_xml_element(
                xml_node,
            )?)),
            "cover" => Ok(SlideTransitionGroup::Cover(EightDirectionTransition::from_xml_element(
                xml_node,
            )?)),
            "cut" => Ok(SlideTransitionGroup::Cut(OptionalBlackTransition::from_xml_element(
                xml_node,
            )?)),
            "diamond" => Ok(SlideTransitionGroup::Diamond),
            "fade" => Ok(SlideTransitionGroup::Fade(OptionalBlackTransition::from_xml_element(
                xml_node,
            )?)),
            "newsflash" => Ok(SlideTransitionGroup::Newsflash),
            "plus" => Ok(SlideTransitionGroup::Plus),
            "pull" => Ok(SlideTransitionGroup::Pull(EightDirectionTransition::from_xml_element(
                xml_node,
            )?)),
            "push" => Ok(SlideTransitionGroup::Push(SideDirectionTransition::from_xml_element(
                xml_node,
            )?)),
            "random" => Ok(SlideTransitionGroup::Random),
            "randomBar" => Ok(SlideTransitionGroup::RandomBar(
                OrientationTransition::from_xml_element(xml_node)?,
            )),
            "split" => Ok(SlideTransitionGroup::Split(SplitTransition::from_xml_element(
                xml_node,
            )?)),
            "strips" => Ok(SlideTransitionGroup::Strips(
                CornerDirectionTransition::from_xml_element(xml_node)?,
            )),
            "wedge" => Ok(SlideTransitionGroup::Wedge),
            "wheel" => Ok(SlideTransitionGroup::Wheel(WheelTransition::from_xml_element(
                xml_node,
            )?)),
            "wipe" => Ok(SlideTransitionGroup::Wipe(SideDirectionTransition::from_xml_element(
                xml_node,
            )?)),
            "zoom" => Ok(SlideTransitionGroup::Zoom(InOutTransition::from_xml_element(xml_node)?)),
            _ => Err(Box::new(NotGroupMemberError::new(
                xml_node.name.clone(),
                "EG_SlideTransition",
            ))),
        }
    }
}

#[derive(Debug, Clone)]
pub struct TransitionStartSoundAction {
    /// This attribute specifies if the sound loops until the next sound event occurs in slideshow.
    ///
    /// Defaults to false
    pub is_looping: Option<bool>,
    /// This element specifies the audio information to play during a slide transition.
    ///
    /// # Xml example
    ///
    /// Consider a slide transition with an audio effect. The <snd> element should be used as follows:
    /// ```xml
    /// <p:transition>
    ///   <p:sndAc>
    ///     <p:stSnd>
    ///       <p:snd r:embed="rId2" />
    ///     </p:stSnd>
    ///   </p:sndAc>
    /// </p:transition>
    /// ```
    pub sound_file: drawingml::EmbeddedWAVAudioFile,
}

impl TransitionStartSoundAction {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let is_looping = match xml_node.attribute("loop") {
            Some(value) => Some(parse_xml_bool(value)?),
            None => None,
        };

        let sound_file_node = xml_node
            .child_nodes
            .get(0)
            .ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "snd"))?;
        let sound_file = drawingml::EmbeddedWAVAudioFile::from_xml_element(sound_file_node)?;

        Ok(Self { is_looping, sound_file })
    }
}

#[derive(Debug, Clone)]
pub enum TransitionSoundAction {
    /// This element describes the sound that starts playing during a slide transition.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:sndAc>
    ///     <p:stSnd>
    ///       <p:snd r:embed="rId2"/>
    ///     </p:stSnd>
    ///   </p:sndAc>
    /// </p:transition>
    /// ```
    StartSound(TransitionStartSoundAction),
    /// This element stops all previous sounds during a slide transition.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:transition>
    ///   <p:sndAc>
    ///     <p:endSnd/>
    ///   </p:sndAc>
    /// </p:transition>
    /// ```
    EndSound,
}

impl TransitionSoundAction {
    pub fn is_choice_member<T>(name: T) -> bool
    where
        T: AsRef<str>,
    {
        match name.as_ref() {
            "stSnd" | "endSnd" => true,
            _ => false,
        }
    }

    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        match xml_node.local_name() {
            "stSnd" => Ok(TransitionSoundAction::StartSound(
                TransitionStartSoundAction::from_xml_element(xml_node)?,
            )),
            "endSnd" => Ok(TransitionSoundAction::EndSound),
            _ => Err(Box::new(NotGroupMemberError::new(
                xml_node.name.clone(),
                "CT_TransitionSoundAction",
            ))),
        }
    }
}

#[derive(Default, Debug, Clone)]
pub struct SlideTransition {
    /// Specifies the transition speed that is to be used when transitioning from the current slide
    /// to the next.
    ///
    /// Defaults to TransitionSpeed::Fast
    pub speed: Option<TransitionSpeed>,
    /// Specifies whether a mouse click advances the slide or not. If this attribute is not specified
    /// then a value of true is assumed.
    ///
    /// Defaults to true
    pub advance_on_click: Option<bool>,
    /// Specifies the time, in milliseconds, after which the transition should start. This setting can
    /// be used in conjunction with the advance_on_click attribute. If this attribute is not specified then it
    /// is assumed that no auto-advance occurs.
    pub advance_on_time: Option<u32>,
    pub transition_type: Option<SlideTransitionGroup>,
    /// This element describes a sound action for slide transition. This element specifies that the start of the slide
    /// transition is accompanied by the playback of an audio file; the actual audio file used is specified by the snd
    /// element
    ///
    /// # Xml example
    ///
    /// Consider a slide transition with a sound effect. The <sndAc> element should be used as follows:
    /// ```xml
    /// <p:transition>
    ///   <p:sndAc>
    ///     <p:stSnd>
    ///       <p:snd r:embed="rId2"/>
    ///     </p:stSnd>
    ///   </p:sndAc>
    /// </p:transition>
    /// ```
    pub sound_action: Option<TransitionSoundAction>,
}

impl SlideTransition {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "spd" => instance.speed = Some(value.parse()?),
                "advClick" => instance.advance_on_click = Some(value.parse()?),
                "advTm" => instance.advance_on_time = Some(value.parse()?),
                _ => (),
            }
        }

        for child_node in &xml_node.child_nodes {
            let child_local_name = child_node.local_name();
            if SlideTransitionGroup::is_choice_member(child_local_name) {
                instance.transition_type = Some(SlideTransitionGroup::from_xml_element(child_node)?);
            } else {
                match child_local_name {
                    "sndAc" => instance.sound_action = Some(TransitionSoundAction::from_xml_element(child_node)?),
                    _ => (),
                }
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct SlideTiming {
    /// This element specifies a list of time node elements used in an animation sequence.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:timing>
    ///   <p:tnLst>
    ///     <p:par> … </p:par>
    ///   </p:tnLst>
    /// </p:timing>
    /// ```
    pub time_node_list: Option<Vec<TimeNodeGroup>>,
    /// This element specifies the list of graphic elements to build. This refers to how the different sub-shapes or sub-
    /// components of a object are displayed. The different objects that can have build properties are text, diagrams,
    /// and charts.
    ///
    /// # Xml example
    ///
    /// ```xml
    /// <p:bldLst>
    ///   <p:bldGraphic spid="1" grpId="0">
    ///     <p:bldSub>
    ///       <a:bldChart bld="category"/>
    ///     </p:bldSub>
    ///   </p:bldGraphic>
    /// </p:bldLst>
    /// ```
    pub build_list: Option<Vec<Build>>,
}

impl SlideTiming {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "tnLst" => {
                    let mut vec = Vec::new();
                    for time_node in &child_node.child_nodes {
                        vec.push(TimeNodeGroup::from_xml_element(time_node)?);
                    }

                    if vec.is_empty() {
                        return Err(Box::new(MissingChildNodeError::new(child_node.name.clone(), "tn")));
                    }

                    instance.time_node_list = Some(vec);
                }
                "bldLst" => {
                    let mut vec = Vec::new();
                    for build_node in &child_node.child_nodes {
                        vec.push(Build::from_xml_element(build_node)?);
                    }

                    if vec.is_empty() {
                        return Err(Box::new(MissingChildNodeError::new(child_node.name.clone(), "bld")));
                    }
                }
                _ => (),
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct HeaderFooter {
    /// Specifies whether the slide number placeholder is enabled. If this attribute is not
    /// specified, a value of true should be assumed by the generating application.
    pub slide_number_enabled: Option<bool>, // true
    /// Specifies whether the Header placeholder is enabled for this master. If this attribute is
    /// not specified, a value of true should be assumed by the generating application.
    pub header_enabled: Option<bool>,
    /// Specifies whether the Footer placeholder is enabled for this master. If this attribute is not
    /// specified, a value of true should be assumed by the generating application.
    pub footer_enabled: Option<bool>,
    /// Specifies whether the Date/Time placeholder is enabled for this master. If this attribute is
    /// not specified, a value of true should be assumed by the generating application.
    pub date_time_enabled: Option<bool>,
}

impl HeaderFooter {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            match attr.as_str() {
                "sldNum" => instance.slide_number_enabled = Some(parse_xml_bool(value)?),
                "hdr" => instance.header_enabled = Some(parse_xml_bool(value)?),
                "ftr" => instance.footer_enabled = Some(parse_xml_bool(value)?),
                "dt" => instance.date_time_enabled = Some(parse_xml_bool(value)?),
                _ => (),
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct Control {
    pub picture: Option<Box<Picture>>,
    pub ole_attributes: Box<OleAttributes>,
}

impl Control {
    pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
        let mut instance: Self = Default::default();

        for (attr, value) in &xml_node.attributes {
            instance.ole_attributes.try_attribute_parse(attr, value)?;
        }

        for child_node in &xml_node.child_nodes {
            match child_node.local_name() {
                "pic" => instance.picture = Some(Box::new(Picture::from_xml_element(child_node)?)),
                _ => (),
            }
        }

        Ok(instance)
    }
}

#[derive(Default, Debug, Clone)]
pub struct OleAttributes {
    pub shape_id: Option<drawingml::ShapeId>,
    /// Specifies the identifying name class used by scripting languages. This name is also used to
    /// construct the clipboard name.
    pub name: Option<String>,
    /// Specifies whether the Embedded object shows as an icon or using its native representation.
    ///
    /// Defaults to false
    pub show_as_icon: Option<bool>,
    /// Specifies the relationship id that is used to identify this Embedded object from within a slide.
    pub id: Option<RelationshipId>,
    /// Specifies the width of the embedded control.
    pub image_width: Option<drawingml::PositiveCoordinate32>,
    /// Specifies the height of the embedded control.
    pub image_height: Option<drawingml::PositiveCoordinate32>,
}

impl OleAttributes {
    pub fn try_attribute_parse<T>(&mut self, attr: T, value: &String) -> Result<()>
    where
        T: AsRef<str>,
    {
        match attr.as_ref() {
            "spid" => self.shape_id = Some(value.parse()?),
            "name" => self.name = Some(value.clone()),
            "showAsIcon" => self.show_as_icon = Some(parse_xml_bool(value)?),
            "r:id" => self.id = Some(value.clone()),
            "imgW" => self.image_width = Some(value.parse()?),
            "imgH" => self.image_height = Some(value.parse()?),
            _ => (),
        }

        Ok(())
    }
}