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
/*
 * DMNTK - Decision Model and Notation Toolkit
 *
 * DMN model and parser
 *
 * Copyright 2018-2021 Dariusz Depta Engos Software <dariusz.depta@engos.software>
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

//! Model for **Decision Requirements Graph** (`DRG`)
//! depicted in one or more **Decision Requirements Diagrams** (`DRD`s).

pub(crate) mod parser;

#[cfg(test)]
mod tests;

use self::errors::*;
use dmntk_feel_parser::dmntk_feel::dmntk_common::{DmntkError, HRef, OptHRef, Result};
use dmntk_feel_parser::dmntk_feel::{FeelType, Name};
use std::convert::TryFrom;

/// [Element] represents an element from another metamodel.
#[derive(Debug, Clone, PartialEq)]
pub struct Element;

/// [DmnElement] is the abstract superclass for the Decision Model elements.
/// It provides the optional attributes `id`, `description` and `label`,
/// which other elements will inherit.
pub trait DmnElement {
  /// Returns reference to optional identifier for this [DmnElement].
  /// This identifier SHALL be unique within its containing [Definitions] element.
  fn id(&self) -> &Option<String>;
  /// Returns reference to optional description of this [DmnElement].
  fn description(&self) -> &Option<String>;
  /// Returns reference to optional alternative short description of this [DmnElement].
  fn label(&self) -> &Option<String>;
  /// Returns reference to attached additional elements to any [DmnElement].
  fn extension_elements(&self) -> &Option<ExtensionElement>;
  /// Returns reference to attached named extended attributes and model associations to any [DmnElement].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute>;
}

/// The [ExtensionElement] element is a container to aggregate elements
/// from other metamodels inside any [DmnElement].
#[derive(Debug, Clone, PartialEq)]
pub struct ExtensionElement {
  pub elements: Vec<Element>,
}

/// The [ExtensionAttribute] element contains an [Element] or a reference
/// to an [Element] from another metamodel. An [ExtensionAttribute] also has a name
/// to define the role or purpose of the associated element.
#[derive(Debug, Clone, PartialEq)]
pub struct ExtensionAttribute {
  /// The name of the extension attribute.
  pub name: String,
  /// The contained [Element].
  /// This attribute SHALL NOT be used together with `value_ref`.
  pub value: Option<Element>,
  /// A reference to the associated [Element].
  /// This attribute SHALL NOT be used together with `value`.
  pub value_ref: Option<Element>,
}

/// [NamedElement] adds the required attribute `name` to [DmnElement].
pub trait NamedElement: DmnElement {
  /// Returns the name of this element.
  fn name(&self) -> &str;
  /// Returns the optional `FEEL` name for this element.
  fn feel_name(&self) -> &Option<Name>;
}

/// [FeelTypedElement] adds the `FEEL` type attributes to element.
pub trait FeelTypedElement {
  /// Returns the optional `FEEL` type for this element.
  fn feel_type(&self) -> &Option<FeelType>;
  /// Sets `FEEL` type for this element.
  fn set_feel_type(&mut self, feel_type: FeelType);
}

/// The abstract class [BusinessContextElement], and its concrete specializations
/// [PerformanceIndicator] and [OrganizationUnit] are placeholders,
/// anticipating a definition to be adopted from other OMG meta-models,
/// such as OMG OSM when it is further developed.
pub trait BusinessContextElement: NamedElement {
  /// The URI of this [BusinessContextElement].
  fn uri(&self) -> &Option<String>;
}

/// Enumeration of concrete instances of [BusinessContextElement].
#[derive(Debug, Clone)]
pub enum BusinessContextElementInstance {
  PerformanceIndicator(PerformanceIndicator),
  OrganizationUnit(OrganizationUnit),
}

///
#[derive(Debug, Clone)]
pub struct PerformanceIndicator {
  /// Optional identifier of this this [InputData].
  id: Option<String>,
  /// Optional description of this [InputData].
  description: Option<String>,
  /// An optional alternative short description of this [InputData].
  label: Option<String>,
  /// Container to attach additional elements to any [InputData].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [InputData].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [PerformanceIndicator].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// The URI of this [PerformanceIndicator].
  uri: Option<String>,
  /// Collection of [Decision] that impact this [PerformanceIndicator].
  /// This attribute stores references
  impacting_decisions: Vec<HRef>,
}

impl DmnElement for PerformanceIndicator {
  /// Returns reference to optional identifier for this [PerformanceIndicator].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [PerformanceIndicator].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [PerformanceIndicator].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [PerformanceIndicator].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [PerformanceIndicator].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for PerformanceIndicator {
  /// Returns a reference to the name of this element.
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl BusinessContextElement for PerformanceIndicator {
  fn uri(&self) -> &Option<String> {
    &self.uri
  }
}

impl PerformanceIndicator {
  pub fn impacting_decisions(&self) -> &Vec<HRef> {
    &self.impacting_decisions
  }
}

///
#[derive(Debug, Clone)]
pub struct OrganizationUnit {
  /// Optional identifier of this this [OrganizationUnit].
  id: Option<String>,
  /// Optional description of this [OrganizationUnit].
  description: Option<String>,
  /// An optional alternative short description of this [OrganizationUnit].
  label: Option<String>,
  /// Container to attach additional elements to any [OrganizationUnit].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [OrganizationUnit].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [OrganizationUnit].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// The URI of this [OrganizationUnit].
  uri: Option<String>,
  /// Collection of [Decision] that are made by this [OrganizationUnit].
  decisions_made: Vec<HRef>,
  /// Collection of [Decision] that are owned by this [OrganizationUnit].
  decisions_owned: Vec<HRef>,
}

impl DmnElement for OrganizationUnit {
  /// Returns reference to optional identifier for this [OrganizationUnit].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [OrganizationUnit].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [OrganizationUnit].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [OrganizationUnit].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [OrganizationUnit].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for OrganizationUnit {
  /// Returns a reference to the name of this element.
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl BusinessContextElement for OrganizationUnit {
  fn uri(&self) -> &Option<String> {
    &self.uri
  }
}

impl OrganizationUnit {
  pub fn decisions_made(&self) -> &Vec<HRef> {
    &self.decisions_made
  }
  pub fn decisions_owned(&self) -> &Vec<HRef> {
    &self.decisions_owned
  }
}

/// In DMN™ model [DrgElement] is the abstract superclass for all DMN™ elements
/// that are contained within [Definitions] and that have a graphical representation in a DRD.
/// This enumeration specifies the list of [DRGElements](DrgElement) contained in [Definitions].
#[derive(Debug, Clone)]
pub enum DrgElement {
  Decision(Decision),
  InputData(InputData),
  BusinessKnowledgeModel(BusinessKnowledgeModel),
  DecisionService(DecisionService),
  KnowledgeSource(KnowledgeSource),
}

impl DrgElement {
  /// Checks if this [DrgElement] has and optional identifier.
  /// If the element with specified identifier exists and
  /// this identifier has a value equal to value specified
  /// in parameter `id` then returns [true].
  /// Otherwise returns [false].
  pub fn has_id(&self, id: &str) -> bool {
    match self {
      DrgElement::Decision(inner) => inner.id().as_ref().map_or(false, |v| v == id),
      DrgElement::InputData(inner) => inner.id().as_ref().map_or(false, |v| v == id),
      DrgElement::BusinessKnowledgeModel(inner) => inner.id().as_ref().map_or(false, |v| v == id),
      DrgElement::DecisionService(inner) => inner.id().as_ref().map_or(false, |v| v == id),
      DrgElement::KnowledgeSource(inner) => inner.id().as_ref().map_or(false, |v| v == id),
    }
  }
  /// Checks if this [DrgElement] has a specified name.
  /// If the element with specified name exists and
  /// this name has a value equal to value specified
  /// in parameter `name` then returns [true].
  /// Otherwise returns [false].
  pub fn has_name(&self, name: &str) -> bool {
    match self {
      DrgElement::Decision(inner) => inner.name().eq(name),
      DrgElement::InputData(inner) => inner.name().eq(name),
      DrgElement::BusinessKnowledgeModel(inner) => inner.name().eq(name),
      DrgElement::DecisionService(inner) => inner.name().eq(name),
      DrgElement::KnowledgeSource(inner) => inner.name().eq(name),
    }
  }
  /// Returns `true` when this [DrgElement] is an instance of [Decision].
  pub fn is_decision(&self) -> bool {
    matches!(self, DrgElement::Decision(_))
  }
  /// Returns `true` when this [DrgElement] is an instance of [InputData].
  pub fn is_input_data(&self) -> bool {
    matches!(self, DrgElement::InputData(_))
  }
  /// Returns `true` when this [DrgElement] is an instance of [BusinessKnowledgeModel].
  pub fn is_business_knowledge_model(&self) -> bool {
    matches!(self, DrgElement::BusinessKnowledgeModel(_))
  }
  /// Returns `true` when this [DrgElement] is an instance of [DecisionService].
  pub fn is_decision_service(&self) -> bool {
    matches!(self, DrgElement::DecisionService(_))
  }
  /// Returns `true` when this [DrgElement] is an instance of [KnowledgeSource].
  pub fn is_knowledge_source(&self) -> bool {
    matches!(self, DrgElement::KnowledgeSource(_))
  }
}

/// [Expression] is an abstract class that describes the logic
/// by which a modeled decision shall be made, or pieces of that logic.
pub trait Expression: DmnElement {
  /// Optional namespace-prefixed name of the base type of this [Expression].
  fn type_ref(&self) -> &Option<String>;
}

pub trait RequiredTypeRef {
  /// Namespace-prefixed name of the base type of the implementor.
  fn type_ref(&self) -> &str;
}

/// [Definitions] element is the outermost containing object
/// for all elements of a DMN decision model.
/// It defines the scope of visibility and the namespace
/// for all contained elements.
#[derive(Debug, Clone)]
pub struct Definitions {
  /// Optional identifier for this [Definitions].
  id: Option<String>,
  /// Optional description of this [Definitions].
  description: Option<String>,
  /// Optional alternative short description of this [Definitions].
  label: Option<String>,
  /// Container to attach additional elements to any [Definitions].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [Definitions].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [Definitions].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// Identifies the namespace associated with this [Definitions]
  /// and follows the convention established by XML Schema.
  namespace: String,
  /// This attribute identifies the expression language used in
  /// [LiteralExpressions](LiteralExpression) within the scope
  /// of this [Definitions]. The `Default` is `FEEL`.
  /// This value `MAY` be overridden on each individual [LiteralExpression].
  /// The language `SHALL` be specified in a URI format.
  expression_language: Option<String>,
  /// This attribute identifies the type language used in
  /// [LiteralExpressions](LiteralExpression) within the scope
  /// of this [Definitions]. The `Default` is `FEEL`.
  /// This value `MAY` be overridden on each individual [ItemDefinition].
  /// The language `SHALL` be specified in a URI format.
  type_language: Option<String>,
  /// Name of the tool used to export the XML serialization.
  exporter: Option<String>,
  /// Version of the tool used to export the XML serialization.
  exporter_version: Option<String>,
  /// Container for the instances of [ItemDefinition] that are contained in this [Definitions].
  item_definitions: Vec<ItemDefinition>,
  /// Container for the instances of [DrgElement] that are contained in this [Definitions].
  drg_elements: Vec<DrgElement>,
  /// Container for the instances of [BusinessContextElement] that are contained in this [Definitions].
  business_context_elements: Vec<BusinessContextElementInstance>,
  /// Reference to the source containing this [Definitions].
  /// This attribute is not a part of specification,
  /// but is handy when importing definitions from other sources.
  source: String,
  /// Optional DMNDI container.
  dmndi: Option<Dmndi>,
}

impl Definitions {
  /// Returns the reference to the namespace associated with this [Definitions].
  pub fn namespace(&self) -> &str {
    &self.namespace
  }
  /// Returns the reference to optional expression language used within the scope of this [Definitions].
  pub fn expression_language(&self) -> &Option<String> {
    &self.expression_language
  }
  /// Returns reference to the type language used within the scope of this [Definitions].
  pub fn type_language(&self) -> &Option<String> {
    &self.type_language
  }
  /// Returns reference to the name of the tool used to export the XML serialization.
  pub fn exporter(&self) -> &Option<String> {
    &self.exporter
  }
  /// Returns reference to the version of the tool used to export the XML serialization.
  pub fn exporter_version(&self) -> &Option<String> {
    &self.exporter_version
  }
  /// Returns reference to the container of instances of [ItemDefinition] contained in this [Definitions].
  pub fn item_definitions(&self) -> &Vec<ItemDefinition> {
    &self.item_definitions
  }
  /// Returns mutable reference to the container of instances of [ItemDefinition] contained in this [Definitions].
  pub fn item_definitions_mut(&mut self) -> &mut Vec<ItemDefinition> {
    &mut self.item_definitions
  }
  /// Returns an optional reference to [ItemDefinition] with specified name
  /// or [None] when such [ItemDefinition] was not found in this [Definitions].
  pub fn item_definition_by_name(&self, name: &str) -> Option<&ItemDefinition> {
    self.item_definitions.iter().find(|v| v.name() == name)
  }
  /// Returns an optional reference to [Decision] with specified identifier
  /// or [None] when such [Decision] was not found among instances of [DrgElement].
  pub fn decision_by_id(&self, id: &str) -> Option<&Decision> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_decision() && v.has_id(id) {
        if let DrgElement::Decision(decision) = v {
          return Some(decision);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [Decision] with specified name
  /// or [None] when such [Decision] was not found among instances of [DrgElement].
  pub fn decision_by_name(&self, name: &str) -> Option<&Decision> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_decision() && v.has_name(name) {
        if let DrgElement::Decision(decision) = v {
          return Some(decision);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [BusinessKnowledgeModel] with specified identifier
  /// or [None] when such [BusinessKnowledgeModel] was not found among instances of [DrgElement].
  pub fn business_knowledge_model_by_id(&self, id: &str) -> Option<&BusinessKnowledgeModel> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_business_knowledge_model() && v.has_id(id) {
        if let DrgElement::BusinessKnowledgeModel(inner) = v {
          return Some(inner);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [BusinessKnowledgeModel] with specified name
  /// or [None] when such [BusinessKnowledgeModel] was not found among instances of [DrgElement].
  pub fn business_knowledge_model_by_name(&self, name: &str) -> Option<&BusinessKnowledgeModel> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_business_knowledge_model() && v.has_name(name) {
        if let DrgElement::BusinessKnowledgeModel(inner) = v {
          return Some(inner);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [DecisionService] with specified identifier
  /// or [None] when such [DecisionService] was not found among instances of [DrgElement].
  pub fn decision_service_by_id(&self, id: &str) -> Option<&DecisionService> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_decision_service() && v.has_id(id) {
        if let DrgElement::DecisionService(inner) = v {
          return Some(inner);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [DecisionService] with specified name
  /// or [None] when such [DecisionService] was not found among instances of [DrgElement].
  pub fn decision_service_by_name(&self, name: &str) -> Option<&DecisionService> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_decision_service() && v.has_name(name) {
        if let DrgElement::DecisionService(inner) = v {
          return Some(inner);
        }
      }
      None
    })
  }
  /// Returns an optional reference to [InputData] with specified identifier
  /// or [None] when such [InputData] was not found among
  /// instances of [DrgElement]).
  pub fn input_data_by_id(&self, id: &str) -> Option<&InputData> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_input_data() && v.has_id(id) {
        if let DrgElement::InputData(input_data) = v {
          return Some(input_data);
        }
      }
      None
    })
  }
  ///
  pub fn input_data(&self) -> Vec<&InputData> {
    self
      .drg_elements
      .iter()
      .filter_map(|v| if let DrgElement::InputData(input_data) = v { Some(input_data) } else { None })
      .collect::<Vec<&InputData>>()
  }
  /// Returns an optional reference to [KnowledgeSource] with specified identifier
  /// or [None] when such [KnowledgeSource] was not found among instances of [DrgElements](DrgElement)).
  pub fn knowledge_source_by_id(&self, id: &str) -> Option<&KnowledgeSource> {
    self.drg_elements.iter().find_map(|v| {
      if v.is_knowledge_source() && v.has_id(id) {
        if let DrgElement::KnowledgeSource(input_data) = v {
          return Some(input_data);
        }
      }
      None
    })
  }
  /// Returns reference to the container of instances of [BusinessContextElement] contained in this [Definitions].
  pub fn business_context_elements(&self) -> &Vec<BusinessContextElementInstance> {
    &self.business_context_elements
  }
  /// Returns reference to optional [Dmndi] container.
  pub fn dmndi(&self) -> &Option<Dmndi> {
    &self.dmndi
  }
  /// Returns reference to [DrgElements](DrgElement) container.
  pub fn drg_elements_mut(&mut self) -> &mut Vec<DrgElement> {
    &mut self.drg_elements
  }
}

impl DmnElement for Definitions {
  /// Returns reference to optional identifier for this [Definitions].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [Definitions].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [Definitions].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [Definitions].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [Definitions].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for Definitions {
  /// Returns reference to the name of this [Definitions].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

#[derive(Debug, Clone, PartialEq)]
pub struct InformationItem {
  /// Optional identifier of this this [InformationItem].
  id: Option<String>,
  /// Optional description of this [InformationItem].
  description: Option<String>,
  /// Optional alternative short description of this [InformationItem].
  label: Option<String>,
  /// Container to attach additional elements to any [InformationItem].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [InformationItem].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [InformationItem].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// The `Expression` whose value is assigned to this [InformationItem].
  value_expression: Option<ExpressionInstance>,
  /// Optional qualified name of the type of this [InformationItem].
  type_ref: Option<String>,
  /// Optional `FEEL` type of this [InformationItem].
  feel_type: Option<FeelType>,
}

impl InformationItem {
  ///
  pub fn value_expression(&self) -> &Option<ExpressionInstance> {
    &self.value_expression
  }
  ///
  pub fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

impl DmnElement for InformationItem {
  /// Returns reference to optional identifier for this [InformationItem].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [InformationItem].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [InformationItem].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [InformationItem].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [InformationItem].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for InformationItem {
  /// Returns reference to the name of this [InformationItem].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl FeelTypedElement for InformationItem {
  /// Returns a reference to optional `FEEL` type of this element.
  fn feel_type(&self) -> &Option<FeelType> {
    &self.feel_type
  }
  /// Sets the `FEEL` type for this element.
  fn set_feel_type(&mut self, feel_type: FeelType) {
    self.feel_type = Some(feel_type);
  }
}

/// [InputData] is used to model the inputs of a decision whose values
/// are defined outside of the decision model.
#[derive(Debug, Clone)]
pub struct InputData {
  /// Optional identifier of this this [InputData].
  id: Option<String>,
  /// Optional description of this [InputData].
  description: Option<String>,
  /// An optional alternative short description of this [InputData].
  label: Option<String>,
  /// Container to attach additional elements to any [InputData].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [InputData].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [InputData].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// The instance of [InformationItem] that stores the result of this [InputData].
  variable: InformationItem,
}

impl InputData {
  pub fn variable(&self) -> &InformationItem {
    &self.variable
  }
}

impl DmnElement for InputData {
  /// Returns reference to optional identifier for this [InputData].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [InputData].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [InputData].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [InputData].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [InputData].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for InputData {
  /// Returns reference to the name of this [InputData].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

/// `Import` class is used when referencing external elements,
/// either DMN DRGElement or ItemDefinition instances contained
/// in other `Definitions` elements, or non-DMN elements,
/// such as an XML Schema or a PMML file.
#[derive(Debug, Clone, PartialEq)]
pub struct Import {
  /// Specifies the style of import associated with this `Import`.
  pub import_type: String,
  /// Identifies the location of the imported element.
  pub location_uri: Option<String>,
  /// Identifies the namespace of the imported element.
  pub namespace: String,
}

/// Enumeration of concrete instances of abstract [Expression], which are:
/// - [LiteralExpression], and
/// - [Invocation].  
#[derive(Debug, Clone, PartialEq)]
pub enum ExpressionInstance {
  Context(Context),
  DecisionTable(DecisionTable),
  FunctionDefinition(Box<FunctionDefinition>),
  Invocation(Box<Invocation>),
  LiteralExpression(LiteralExpression),
  UnaryTests,
  Relation(Relation),
}

/// A [Context] is composed of any number of model context entries, which are instances of [ContextEntry].
#[derive(Debug, Clone, PartialEq)]
pub struct Context {
  /// This attribute lists the instances of [ContextEntry] that compose this [Context].
  context_entries: Vec<ContextEntry>,
}

impl Context {
  /// Return a reference to context entries that compose this [Context].
  pub fn context_entries(&self) -> &Vec<ContextEntry> {
    &self.context_entries
  }
}

/// The class [ContextEntry] is used to model `FEEL` context entries when a context is modeled as a [Context] element.
#[derive(Debug, Clone, PartialEq)]
pub struct ContextEntry {
  /// The instance of [InformationItem] that is contained in this [ContextEntry],
  /// and whose name is the key in the modeled context entry.
  variable: Option<InformationItem>,
  /// The instance of [Expression] that is the expression in this [ContextEntry].
  value: ExpressionInstance,
}

/// [LiteralExpression] is used to model a value expression whose value
/// is specified by text in some specified expression language.
#[derive(Debug, Clone, PartialEq)]
pub struct LiteralExpression {
  /// Optional identifier of this this [LiteralExpression].
  id: Option<String>,
  /// Optional description of this [LiteralExpression].
  description: Option<String>,
  /// An optional alternative short description of this [LiteralExpression].
  label: Option<String>,
  /// Container to attach additional elements to any [LiteralExpression].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [LiteralExpression].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Optional type definition for this [LiteralExpression].
  type_ref: Option<String>,
  /// The text of this [LiteralExpression].
  /// It SHALL be a valid expression in the `expression_language`.
  text: Option<String>,
  /// Identifies the expression language used in this [LiteralExpression].
  expression_language: Option<String>,
  /// The instance of [ImportedValue](Import) that specifies
  /// where the text of this [LiteralExpression] is located.
  imported_values: Option<Import>,
}

impl LiteralExpression {
  pub fn text(&self) -> &Option<String> {
    &self.text
  }
  pub fn expression_language(&self) -> Option<String> {
    self.expression_language.clone()
  }
  pub fn imported_values(&self) -> Option<Import> {
    self.imported_values.clone()
  }
}

impl DmnElement for LiteralExpression {
  /// Returns reference to optional identifier for this [LiteralExpression].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [LiteralExpression].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [LiteralExpression].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [LiteralExpression].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [LiteralExpression].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl Expression for LiteralExpression {
  fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

/// [Invocation] is a mechanism that permits the evaluation of one value expression – the invoked expression – inside
/// another value expression – the invoking expression – by binding locally the input variables of the invoked
/// expression to values inside the invoking expression.
#[derive(Debug, Clone, PartialEq)]
pub struct Invocation {
  /// An expression whose value is a function.
  called_function: ExpressionInstance,
  /// Instances of [Binding] used to bind the formalParameters
  /// of the `called_function` in this [Invocation].
  bindings: Vec<Binding>,
}

impl Invocation {
  /// Returns a reference to called function which is an instance of [Expression].
  pub fn called_function(&self) -> &ExpressionInstance {
    &self.called_function
  }
  /// Returns a reference to the collection of binding instances.
  pub fn bindings(&self) -> &Vec<Binding> {
    &self.bindings
  }
}

#[derive(Debug, Clone, PartialEq)]
pub struct Binding {
  /// The [InformationItem] on which the `calledFunction` of the owning
  /// instance of [Invocation] depends that is bound by this [Binding].
  parameter: InformationItem,
  /// The instance of [Expression] to which the parameter in this [Binding] is
  /// bound when the owning instance of [Invocation] is evaluated.
  binding_formula: Option<ExpressionInstance>,
}

impl Binding {
  /// Returns a reference to parameter.
  pub fn parameter(&self) -> &InformationItem {
    &self.parameter
  }
  /// Returns a reference to binding formula.
  pub fn binding_formula(&self) -> &Option<ExpressionInstance> {
    &self.binding_formula
  }
}

/// [Decision]
#[derive(Debug, Clone)]
pub struct Decision {
  /// Identifier of the [Decision].
  id: Option<String>,
  /// Description of the [Decision].
  description: Option<String>,
  /// An alternative short description of the [Decision].
  label: Option<String>,
  /// Container to attach additional elements to any [Decision].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [Decision].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of the [Decision].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// A natural language question that characterizes the [Decision],
  /// such that the output of the [Decision] is an answer to the question.
  question: Option<String>,
  /// A natural language description of the answers allowed for the question
  /// such as `Yes/No`, a list of allowed values, a range of numeric values etc.
  allowed_answers: Option<String>,
  /// The instance of [InformationItem] that stores the result of this [Decision].
  variable: InformationItem,
  /// The instance of the [Expression] for the [Decision].
  decision_logic: Option<ExpressionInstance>,
  /// Collection of the instances of [InformationRequirement] that compose this [Decision].
  information_requirements: Vec<InformationRequirement>,
  /// Collection of the instances of [KnowledgeRequirement] that compose this [Decision].
  knowledge_requirements: Vec<KnowledgeRequirement>,
  //TODO add the following:
  // authority_requirements
  // supported_objectives
  // impacted_performance_indicator
  // decision_maker
  // decision_owner
  // using_processes
  // using_tasks
}

impl Decision {
  /// Return a reference to a variable that stores the result of this [Decision].
  pub fn variable(&self) -> &InformationItem {
    &self.variable
  }
  /// Returns a reference to optional [Expression].
  pub fn decision_logic(&self) -> &Option<ExpressionInstance> {
    &self.decision_logic
  }
  /// Returns a reference to collection of [InformationRequirement].
  pub fn information_requirements(&self) -> &Vec<InformationRequirement> {
    &self.information_requirements
  }
  /// Returns a reference to collection of [KnowledgeRequirement].
  pub fn knowledge_requirements(&self) -> &Vec<KnowledgeRequirement> {
    &self.knowledge_requirements
  }
}

impl DmnElement for Decision {
  /// Returns reference to optional identifier for this [Decision].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [Decision].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [Decision].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [Decision].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [Decision].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for Decision {
  /// Returns reference to the name of this [Decision].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

/// The class [InformationRequirement] is used to model an information requirement,
/// as represented by a plain arrow in a DRD.
#[derive(Debug, Clone)]
pub struct InformationRequirement {
  /// Optional identifier of the [InformationRequirement].
  id: Option<String>,
  /// Optional description of the [InformationRequirement].
  description: Option<String>,
  /// An optional alternative short description of the [InformationRequirement].
  label: Option<String>,
  /// Container to attach additional elements to any [InformationRequirement].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [InformationRequirement].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Reference to [Decision] that this [InformationRequirement] associates
  /// with its containing  [Decision] element.
  required_decision: OptHRef,
  /// Reference to [InputData] that this [InformationRequirement] associates
  /// with its containing [Decision] element.
  required_input: OptHRef,
}

impl InformationRequirement {
  /// Returns reference to optional URI pointing [Decision].
  pub fn required_decision(&self) -> &OptHRef {
    &self.required_decision
  }
  /// Returns reference to optional URI pointing [InputData].
  pub fn required_input(&self) -> &OptHRef {
    &self.required_input
  }
}

impl DmnElement for InformationRequirement {
  /// Returns reference to optional identifier for this [InformationRequirement].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [InformationRequirement].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [InformationRequirement].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [InformationRequirement].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [InformationRequirement].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

/// The class [KnowledgeRequirement] is used to model a knowledge requirement,
/// as represented by a dashed arrow in a DRD.
#[derive(Debug, Clone)]
pub struct KnowledgeRequirement {
  /// Optional identifier of the [KnowledgeRequirement].
  id: Option<String>,
  /// Optional description of the [KnowledgeRequirement].
  description: Option<String>,
  /// An optional alternative short description of the [KnowledgeRequirement].
  label: Option<String>,
  /// Container to attach additional elements to any [KnowledgeRequirement].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [KnowledgeRequirement].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Reference to [Invocable] that this [KnowledgeRequirement] associates with
  /// its containing [Decision] or [BusinessKnowledgeModel] element.
  required_knowledge: OptHRef,
}

impl KnowledgeRequirement {
  /// Returns reference to the [Invocable].
  pub fn required_knowledge(&self) -> &OptHRef {
    &self.required_knowledge
  }
}

impl DmnElement for KnowledgeRequirement {
  /// Returns reference to optional identifier for this [KnowledgeRequirement].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [KnowledgeRequirement].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [KnowledgeRequirement].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [KnowledgeRequirement].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [KnowledgeRequirement].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

/// The class [AuthorityRequirement] is used to model an authority requirement,
/// as represented by an arrow drawn with a dashed line and a filled circular head in a DRD
#[derive(Debug, Clone)]
pub struct AuthorityRequirement {
  /// Optional identifier of the [AuthorityRequirement].
  id: Option<String>,
  /// Optional description of the [AuthorityRequirement].
  description: Option<String>,
  /// An optional alternative short description of the [AuthorityRequirement].
  label: Option<String>,
  /// Container to attach additional elements to any [AuthorityRequirement].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [AuthorityRequirement].
  extension_attributes: Vec<ExtensionAttribute>,
  /// The instance of [KnowledgeSource] that this [AuthorityRequirement] associates
  /// with its containing [KnowledgeSource], [Decision] or [BusinessKnowledgeModel] element.
  required_authority: Option<KnowledgeSource>,
  /// The instance of [Decision] that this [AuthorityRequirement] associates
  /// with its containing [KnowledgeSource] element.
  required_decision: Option<Decision>,
  /// The instance of [InputData] that this [AuthorityRequirement] associates
  /// with its containing [KnowledgeSource] element.
  required_input: Option<InputData>,
}

impl AuthorityRequirement {
  /// Returns reference to optional [KnowledgeSource].
  pub fn required_authority(&self) -> &Option<KnowledgeSource> {
    &self.required_authority
  }
  /// Returns reference to optional [Decision].
  pub fn required_decision(&self) -> &Option<Decision> {
    &self.required_decision
  }
  /// Returns reference to optional [InputData].
  pub fn required_input(&self) -> &Option<InputData> {
    &self.required_input
  }
}

impl DmnElement for AuthorityRequirement {
  /// Returns reference to optional identifier for this [AuthorityRequirement].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [AuthorityRequirement].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [AuthorityRequirement].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [AuthorityRequirement].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [AuthorityRequirement].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

/// The class [KnowledgeSource] is used to model authoritative knowledge sources in a decision model.
/// In a DRD, an instance of [KnowledgeSource] is represented by a `knowledge source` diagram element.
#[derive(Debug, Clone)]
pub struct KnowledgeSource {
  /// Optional identifier of this this [KnowledgeSource].
  id: Option<String>,
  /// Optional description of this [KnowledgeSource].
  description: Option<String>,
  /// Optional alternative short description of this [KnowledgeSource].
  label: Option<String>,
  /// Container to attach additional elements to any [KnowledgeSource].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [KnowledgeSource].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [KnowledgeSource].
  name: String,
  /// Optional `FEEL` name of this [KnowledgeSource].
  feel_name: Option<Name>,
}

impl DmnElement for KnowledgeSource {
  /// Returns reference to optional identifier for this [KnowledgeSource].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [KnowledgeSource].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [KnowledgeSource].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [KnowledgeSource].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [KnowledgeSource].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for KnowledgeSource {
  /// Returns reference to the name of this [KnowledgeSource].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this [KnowledgeSource].
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

/// `Invocable` is used to model the inputs of a decision whose values
/// are defined outside of the decision model.
pub trait Invocable: DmnElement + NamedElement {
  /// Returns reference to a variable that is bound to the
  /// function defined by the [FunctionDefinition], allowing
  /// decision logic to invoke the function by name.
  fn variable(&self) -> &InformationItem;
}

/// Instances of `Invocable` interface.
#[derive(Debug, Clone)]
pub enum InvocableInstance {
  BusinessKnowledgeModel(BusinessKnowledgeModel),
  DecisionService, // TODO add DecisionService
}

/// A business knowledge model has an abstract part, representing reusable,
/// invocable decision logic, and a concrete part, which mandates that the decision logic
/// must be a single FEEL boxed function definition.
#[derive(Debug, Clone)]
pub struct BusinessKnowledgeModel {
  /// Optional identifier of this this [BusinessKnowledgeModel].
  id: Option<String>,
  /// Optional description of this [BusinessKnowledgeModel].
  description: Option<String>,
  /// Optional alternative short description of this [BusinessKnowledgeModel].
  label: Option<String>,
  /// Container to attach additional elements to any [BusinessKnowledgeModel].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [BusinessKnowledgeModel].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [BusinessKnowledgeModel].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// Variable that is bound to the function defined by the [FunctionDefinition] for this [BusinessKnowledgeModel].
  variable: InformationItem,
  /// The function that encapsulates the logic encapsulated by this [BusinessKnowledgeModel].
  encapsulated_logic: Option<FunctionDefinition>,
  /// This attribute lists the instances of [KnowledgeRequirement] that compose this [BusinessKnowledgeModel].
  knowledge_requirements: Vec<KnowledgeRequirement>,
  /// This attribute lists the instances of [AuthorityRequirement] that compose this [BusinessKnowledgeModel].
  authority_requirements: Vec<AuthorityRequirement>,
}

impl BusinessKnowledgeModel {
  /// Returns reference to a variable for this [BusinessKnowledgeModel].
  pub fn encapsulated_logic(&self) -> &Option<FunctionDefinition> {
    &self.encapsulated_logic
  }
  /// Returns reference to the collection of instances of [KnowledgeRequirement] that compose this [BusinessKnowledgeModel].
  pub fn knowledge_requirements(&self) -> &Vec<KnowledgeRequirement> {
    &self.knowledge_requirements
  }
  /// Returns reference to the collection of instances of [AuthorityRequirement] that compose this [BusinessKnowledgeModel].
  pub fn authority_requirements(&self) -> &Vec<AuthorityRequirement> {
    &self.authority_requirements
  }
}

impl DmnElement for BusinessKnowledgeModel {
  /// Returns reference to optional identifier for this [BusinessKnowledgeModel].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [BusinessKnowledgeModel].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [BusinessKnowledgeModel].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [BusinessKnowledgeModel].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [BusinessKnowledgeModel].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for BusinessKnowledgeModel {
  /// Returns reference to the name of this [ItemDefinition].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl Invocable for BusinessKnowledgeModel {
  /// Returns reference to a variable for this [BusinessKnowledgeModel].
  fn variable(&self) -> &InformationItem {
    &self.variable
  }
}

/// The [DecisionService] class is used to define named decision services
/// against the decision model contained in an instance of [Definitions].
#[derive(Debug, Clone)]
pub struct DecisionService {
  /// Optional identifier of this this [DecisionService].
  id: Option<String>,
  /// Optional description of this [DecisionService].
  description: Option<String>,
  /// Optional alternative short description of this [DecisionService].
  label: Option<String>,
  /// Container to attach additional elements to any [DecisionService].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [DecisionService].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [DecisionService].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// Variable for this [DecisionService].
  variable: InformationItem,
  /// Collection of references to the instances of [Decision] required to be output by this [DecisionService].
  output_decisions: Vec<HRef>,
  /// Collection of references to the instances of [Decision] to be encapsulated in this [DecisionService].
  encapsulated_decisions: Vec<HRef>,
  /// Collection of references to the instances of [Decision] required as input by this [DecisionService].
  input_decisions: Vec<HRef>,
  /// Collection of references to the instances of [InputData] required as input by this [DecisionService].
  input_data: Vec<HRef>,
}

impl DecisionService {
  /// Returns a reference to collection of references to output [Decision]s for this [DecisionService].
  pub fn output_decisions(&self) -> &Vec<HRef> {
    &self.output_decisions
  }
  /// Returns a reference to collection of references to encapsulated [Decision]s for this [DecisionService].
  pub fn encapsulated_decisions(&self) -> &Vec<HRef> {
    &self.encapsulated_decisions
  }
  /// Returns a reference to collection of references to input [Decision]s for this [DecisionService].
  pub fn input_decisions(&self) -> &Vec<HRef> {
    &self.input_decisions
  }
  /// Returns a reference to collection of references to [InputData] for this [DecisionService].
  pub fn input_data(&self) -> &Vec<HRef> {
    &self.input_data
  }
}

impl DmnElement for DecisionService {
  /// Returns reference to optional identifier for this [DecisionService].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [DecisionService].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [DecisionService].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [DecisionService].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [DecisionService].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for DecisionService {
  /// Returns reference to the name of this [ItemDefinition].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl Invocable for DecisionService {
  /// Returns reference to a variable for this [DecisionService].
  fn variable(&self) -> &InformationItem {
    &self.variable
  }
}

/// Item definition types.
#[derive(Debug, Clone)]
pub enum ItemDefinitionType {
  SimpleType(FeelType),
  ReferencedType(String),
  ComponentType,
  CollectionOfSimpleType(FeelType),
  CollectionOfReferencedType(String),
  CollectionOfComponentType,
}

/// [ItemDefinition] is used to model the inputs of a decision,
/// whose values are defined outside of the decision model.
#[derive(Debug, Clone)]
pub struct ItemDefinition {
  /// Optional identifier of this this [ItemDefinition].
  id: Option<String>,
  /// Optional description of this [ItemDefinition].
  description: Option<String>,
  /// Optional alternative short description of this [ItemDefinition].
  label: Option<String>,
  /// Container to attach additional elements to any [ItemDefinition].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [ItemDefinition].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Name of this [ItemDefinition].
  name: String,
  /// Optional `FEEL` name of this [ItemDefinition].
  feel_name: Option<Name>,
  /// Optional base type of this [ItemDefinition] identified by namespace-prefixed name.
  type_ref: Option<String>,
  /// This attribute identifies the type language used to specify the base
  /// type of this [ItemDefinition]. This value overrides the type
  /// language specified in the [Definitions] element. The default is `FEEL`.
  /// The language `SHALL` be specified in an URI format.
  type_language: Option<String>,
  /// This attribute contains `FEEL` built-in type only when the `type_language` attribute
  /// is `FEEL` and the `type_ref` attribute defines one of the built-in `FEEL` types.
  feel_type: Option<FeelType>,
  /// Possible values or ranges of values in the base type that are allowed in this [ItemDefinition].
  allowed_values: Option<UnaryTests>,
  /// Defines zero or more nested [ItemDefinitions](ItemDefinition) that compose this [ItemDefinition].
  item_components: Vec<ItemDefinition>,
  /// Setting this flag to true indicates that the actual values defined by
  /// this [ItemDefinition] are collections of allowed values.
  /// The default value is [false].
  is_collection: bool,
  /// Describes an optional [FunctionItem] that compose this [ItemDefinition].
  function_item: Option<FunctionItem>,
  /// Optional item definition type.
  item_definition_type: Option<ItemDefinitionType>,
}

impl ItemDefinition {
  /// Returns reference to the type language used within the scope of this [ItemDefinition].
  pub fn type_language(&self) -> &Option<String> {
    &self.type_language
  }
  /// Returns reference to possible values or ranges of values
  /// in the base type that are allowed in this [ItemDefinition].
  pub fn allowed_values(&self) -> &Option<UnaryTests> {
    &self.allowed_values
  }
  /// Returns reference to nested [ItemDefinitions](ItemDefinition) that compose this [ItemDefinition].
  pub fn item_components(&self) -> &Vec<ItemDefinition> {
    &self.item_components
  }
  /// Returns mutable reference to nested [ItemDefinitions](ItemDefinition) that compose this [ItemDefinition].
  pub fn item_components_mut(&mut self) -> &mut Vec<ItemDefinition> {
    &mut self.item_components
  }
  /// Returns flag indicating if the actual values are collections of allowed values.
  pub fn is_collection(&self) -> bool {
    self.is_collection
  }
  /// Returns a reference to optional `FEEL` type.
  pub fn feel_type(&self) -> &Option<FeelType> {
    &self.feel_type
  }
  /// Sets the `FEEL` type for this element.
  pub fn set_feel_type(&mut self, feel_type: FeelType) {
    self.feel_type = Some(feel_type);
  }
  /// Returns a reference to optional item definition type.
  pub fn item_definition_type(&self) -> &Option<ItemDefinitionType> {
    &self.item_definition_type
  }
  /// Sets the item definition type for this element.
  pub fn set_item_definition_type(&mut self, item_definition_type: ItemDefinitionType) {
    self.item_definition_type = Some(item_definition_type);
  }
}

impl DmnElement for ItemDefinition {
  /// Returns reference to optional identifier for this [ItemDefinition].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [ItemDefinition].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [ItemDefinition].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [ItemDefinition].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [ItemDefinition].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl NamedElement for ItemDefinition {
  /// Returns reference to the name of this [ItemDefinition].
  fn name(&self) -> &str {
    &self.name
  }
  /// Returns a reference to optional `FEEL` name of this element.
  fn feel_name(&self) -> &Option<Name> {
    &self.feel_name
  }
}

impl Expression for ItemDefinition {
  fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

/// [UnaryTests] is used to model a boolean test, where the argument
/// to be tested is implicit or denoted with a **?**.
/// Test is specified by text in some specified expression language.
#[derive(Debug, Clone)]
pub struct UnaryTests {
  /// The text of this [UnaryTests].
  /// It SHALL be a valid expression in the expressionLanguage.
  text: Option<String>,
  /// This attribute identifies the expression language used in this [UnaryTests].
  /// This value overrides the expression language specified for the containing
  /// instance of DecisionRequirementDiagram.
  /// The language SHALL be specified in a URI format.
  expression_language: Option<String>,
}

impl UnaryTests {
  /// Returns reference to optional text of this [UnaryTests].
  pub fn text(&self) -> &Option<String> {
    &self.text
  }
  /// Returns reference to optional expression language used in this [UnaryTests].
  pub fn expression_language(&self) -> &Option<String> {
    &self.expression_language
  }
}

/// [FunctionItem] defines the signature of a function:
/// the parameters and the output type of the function.
#[derive(Debug, Clone)]
pub struct FunctionItem {
  /// Reference to output type of the function.
  output_type_ref: Option<String>,
  /// Function parameters as [InformationItems](InformationItem).
  parameters: Vec<InformationItem>,
}

impl FunctionItem {
  /// Returns reference to output type of function.
  pub fn output_type_ref(&self) -> &Option<String> {
    &self.output_type_ref
  }
  /// Returns reference to function parameters defined
  /// as collection of [InformationItems](InformationItem).
  pub fn parameters(&self) -> &Vec<InformationItem> {
    &self.parameters
  }
}

/// Defines the type of the [FunctionDefinition].
/// The default value is `FEEL`. Supported values also include `Java` and `PMML`.
#[derive(Debug, Clone, PartialEq)]
pub enum FunctionKind {
  Feel,
  Java,
  Pmml,
}

/// [FunctionItem] defines the signature of a function:
/// the parameters and the output type of the function.
#[derive(Debug, Clone, PartialEq)]
pub struct FunctionDefinition {
  /// Optional identifier of this this [FunctionDefinition].
  id: Option<String>,
  /// Optional description of this [FunctionDefinition].
  description: Option<String>,
  /// Optional alternative short description of this [FunctionDefinition].
  label: Option<String>,
  /// Container to attach additional elements to any [FunctionDefinition].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [FunctionDefinition].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Optional base type of this [FunctionDefinition] identified by namespace-prefixed name.
  type_ref: Option<String>,
  /// Container for instances of [InformationItem] that are the parameters of this [FunctionDefinition].
  formal_parameters: Vec<InformationItem>,
  /// The instance of [Expression] that is the body in this [FunctionDefinition].
  body: Option<ExpressionInstance>,
  /// Type of this [FunctionDefinition], the default value is FEEL.
  kind: FunctionKind,
}

impl FunctionDefinition {
  /// Returns reference to container of [InformationItem] of this [FunctionDefinition].
  pub fn formal_parameters(&self) -> &Vec<InformationItem> {
    &self.formal_parameters
  }
  /// Returns reference to [Expression] that is the body in this [FunctionDefinition].
  pub fn body(&self) -> &Option<ExpressionInstance> {
    &self.body
  }
  /// Returns the type of this [FunctionDefinition].
  pub fn kind(&self) -> &FunctionKind {
    &self.kind
  }
}

impl DmnElement for FunctionDefinition {
  /// Returns reference to optional identifier for this [FunctionDefinition].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [FunctionDefinition].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [FunctionDefinition].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [FunctionDefinition].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [FunctionDefinition].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl Expression for FunctionDefinition {
  fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

/// A [Relation] is convenient shorthand for a list of similar contexts.
/// A [Relation] has a column instead of repeated `ContextEntry`s,
/// and a `List` is used for every row, with one of the `List`’s
/// expression for each column value.
#[derive(Debug, Clone, PartialEq)]
pub struct Relation {
  /// Optional identifier of this this [Relation].
  id: Option<String>,
  /// Optional description of this [Relation].
  description: Option<String>,
  /// Optional alternative short description of this [Relation].
  label: Option<String>,
  /// Container to attach additional elements to any [Relation].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [Relation].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Optional base type of this [Relation] identified by namespace-prefixed name.
  type_ref: Option<String>,
  /// This attribute lists the instances of [List] that are the rows in this [Relation].
  rows: Vec<List>,
  /// This attributes lists the instances of [InformationItem] that define the columns in this [Relation].
  columns: Vec<InformationItem>,
}

impl Relation {
  /// Returns a reference to collection of relation's rows.
  pub fn rows(&self) -> &Vec<List> {
    &self.rows
  }
  /// Returns a reference to collection of relation's columns.
  pub fn columns(&self) -> &Vec<InformationItem> {
    &self.columns
  }
}

impl DmnElement for Relation {
  /// Returns reference to optional identifier for this [FunctionDefinition].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [FunctionDefinition].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [FunctionDefinition].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [FunctionDefinition].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [FunctionDefinition].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl Expression for Relation {
  fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

/// A [List] is simply a list of elements, which are instances of [Expression]s.
#[derive(Debug, Clone, PartialEq)]
pub struct List {
  /// Optional identifier of this this [List].
  id: Option<String>,
  /// Optional description of this [List].
  description: Option<String>,
  /// Optional alternative short description of this [List].
  label: Option<String>,
  /// Container to attach additional elements to any [List].
  extension_elements: Option<ExtensionElement>,
  /// Container to attach named extended attributes and model associations to any [List].
  extension_attributes: Vec<ExtensionAttribute>,
  /// Optional base type of this [List] identified by namespace-prefixed name.
  type_ref: Option<String>,
  /// This attribute lists the instances of [Expression] that are the elements in this [List].
  elements: Vec<ExpressionInstance>,
}

impl List {
  /// Returns a reference to collection of list's elements.
  pub fn elements(&self) -> &Vec<ExpressionInstance> {
    &self.elements
  }
}

impl DmnElement for List {
  /// Returns reference to optional identifier for this [FunctionDefinition].
  fn id(&self) -> &Option<String> {
    &self.id
  }
  /// Returns reference to optional description of this [FunctionDefinition].
  fn description(&self) -> &Option<String> {
    &self.description
  }
  /// Returns reference to optional alternative short description of this [FunctionDefinition].
  fn label(&self) -> &Option<String> {
    &self.label
  }
  /// Returns reference to attached additional elements to any [FunctionDefinition].
  fn extension_elements(&self) -> &Option<ExtensionElement> {
    &self.extension_elements
  }
  /// Returns reference to attached named extended attributes and model associations to any [FunctionDefinition].
  fn extension_attributes(&self) -> &Vec<ExtensionAttribute> {
    &self.extension_attributes
  }
}

impl Expression for List {
  fn type_ref(&self) -> &Option<String> {
    &self.type_ref
  }
}

/// Decision table.
#[derive(Debug, Clone, PartialEq)]
pub struct DecisionTable {
  /// Information item name, for which the decision table is its value expression.
  /// This is usually the name of the decision or the name of business knowledge model for
  /// which the decision table provides the decision logic.
  pub information_item_name: Option<String>,
  /// List of instances of input clause that compose this decision table.
  pub input_clauses: Vec<InputClause>,
  /// List of instances of output clause that compose this decision table.
  pub output_clauses: Vec<OutputClause>,
  /// List of instances of rule annotation clause that compose this decision table.
  pub annotations: Vec<RuleAnnotationClause>,
  /// List of instances of decision rule that compose this decision table.
  pub rules: Vec<DecisionRule>,
  /// Hit policy associated with the instance of the decision table.
  pub hit_policy: HitPolicy,
  /// Optional aggregation type when the hit policy is `COLLECT`.
  pub aggregation: Option<BuiltinAggregator>,
  /// Preferred representation of the instance of the decision table.
  pub preferred_orientation: DecisionTableOrientation,
  /// Optional output label for the description of the decision table output,
  /// may be the same as the name of the information item for which the
  /// decision table is the value expression.
  pub output_label: Option<String>,
}

/// Implementation of Display trait for DecisionTable.
impl std::fmt::Display for DecisionTable {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    let mut buffer = String::new();
    buffer.push_str("Decision table:\n");
    buffer.push_str(format!(">> preferred orientation: {}\n", self.preferred_orientation).as_str());
    buffer.push_str(">> information item name: ");
    if let Some(text) = &self.information_item_name {
      buffer.push_str(format!("\n'{}'\n", text).as_str());
    } else {
      buffer.push_str("none\n");
    }
    buffer.push_str(format!(">> hit policy: {}\n", self.hit_policy).as_str());
    buffer.push_str(">> aggregation: ");
    if let Some(aggregation) = &self.aggregation {
      buffer.push_str(format!("{}\n", aggregation).as_str());
    } else {
      buffer.push_str("none\n");
    }
    buffer.push_str(">> output label: ");
    if let Some(text) = &self.output_label {
      buffer.push_str(format!("\n'{}'\n", text).as_str());
    } else {
      buffer.push_str("none\n");
    }
    write!(f, "{}", buffer)
  }
}

/// Orientation of the decision table.
#[derive(Debug, Clone, PartialEq)]
pub enum DecisionTableOrientation {
  /// Decision table is presented horizontally, rules are presented as rows.
  RuleAsRow,
  /// Decision table is presented vertically, rules are presented as columns.
  RuleAsColumn,
  /// Decision table is presented as crosstab, rules are composed from two input dimensions.
  CrossTable,
}

/// Implementation of Display trait for DecisionTableOrientation.
impl std::fmt::Display for DecisionTableOrientation {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    match self {
      DecisionTableOrientation::RuleAsRow => write!(f, "Rule-as-Row"),
      DecisionTableOrientation::RuleAsColumn => write!(f, "Rule-as-Column"),
      DecisionTableOrientation::CrossTable => write!(f, "CrossTable"),
    }
  }
}

impl TryFrom<&str> for DecisionTableOrientation {
  type Error = DmntkError;
  /// Tries to construct a decision table orientation from its text representation.
  fn try_from(value: &str) -> Result<Self, Self::Error> {
    match value.trim() {
      "Rule-as-Row" => Ok(DecisionTableOrientation::RuleAsRow),
      "Rule-as-Column" => Ok(DecisionTableOrientation::RuleAsColumn),
      "CrossTable" => Ok(DecisionTableOrientation::CrossTable),
      other => Err(invalid_decision_table_orientation(other)),
    }
  }
}

/// Hit policy.
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum HitPolicy {
  /// `UNIQUE` hit policy. No overlapping rules are allowed, only single rule can be matched.
  /// This is the default value for hit policy (DMN 1.2 clause 8.2.10).
  /// Crosstab decision tables may have only unique hit policy.
  Unique,
  /// `ANY` hit policy. Rules may overlap, but all matching rules show equal output entries.
  /// If matching rules have non-equal output entries, this policy is incorrect and the
  /// result is undefined.
  Any,
  /// `PRIORITY` hit policy. Multiple rules can match, with different output entries for each output.
  /// This policy returns matching rule with the highest priority.
  /// Output priorities are specified in the ordered list of output values,
  /// in decreasing order of priority.
  Priority,
  /// `FIRST` hit policy...
  First,
  /// `COLLECT` hit policy...
  Collect(BuiltinAggregator),
  /// `OUTPUT ORDER` hit policy...
  OutputOrder,
  /// `RULE ORDER` hit policy...
  RuleOrder,
}

/// Implementation of Display trait for HitPolicy.
impl std::fmt::Display for HitPolicy {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    match self {
      HitPolicy::Unique => write!(f, "UNIQUE"),
      HitPolicy::Any => write!(f, "ANY"),
      HitPolicy::Priority => write!(f, "PRIORITY"),
      HitPolicy::First => write!(f, "FIRST"),
      HitPolicy::Collect(aggregator) => write!(f, "COLLECT {}", aggregator),
      HitPolicy::OutputOrder => write!(f, "OUTPUT ORDER"),
      HitPolicy::RuleOrder => write!(f, "RULE ORDER"),
    }
  }
}

impl TryFrom<&str> for HitPolicy {
  type Error = DmntkError;
  /// Tries to construct a hit policy from its text representation.
  fn try_from(value: &str) -> Result<Self, Self::Error> {
    match value.trim() {
      "U" => Ok(HitPolicy::Unique),
      "A" => Ok(HitPolicy::Any),
      "P" => Ok(HitPolicy::Priority),
      "F" => Ok(HitPolicy::First),
      "R" => Ok(HitPolicy::RuleOrder),
      "O" => Ok(HitPolicy::OutputOrder),
      "C" => Ok(HitPolicy::Collect(BuiltinAggregator::List)),
      "C+" => Ok(HitPolicy::Collect(BuiltinAggregator::Sum)),
      "C#" => Ok(HitPolicy::Collect(BuiltinAggregator::Count)),
      "C<" => Ok(HitPolicy::Collect(BuiltinAggregator::Min)),
      "C>" => Ok(HitPolicy::Collect(BuiltinAggregator::Max)),
      other => Err(invalid_decision_table_hit_policy(other)),
    }
  }
}

/// Aggregator function for **COLLECT** hit policy.
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum BuiltinAggregator {
  /// The result of the decision table is a list of output entries.
  List,
  /// The result of the decision table is the number of outputs.
  Count,
  /// The result of the decision table is the sum of all the outputs.
  Sum,
  /// The result of the decision table is the smallest value of all the outputs.
  Min,
  /// The result of the decision table is the largest value of all the outputs.
  Max,
}

/// Implementation of Display trait for BuiltinAggregator.
impl std::fmt::Display for BuiltinAggregator {
  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
    write!(
      f,
      "{}",
      match self {
        BuiltinAggregator::List => "LIST",
        BuiltinAggregator::Count => "COUNT",
        BuiltinAggregator::Sum => "SUM",
        BuiltinAggregator::Min => "MIN",
        BuiltinAggregator::Max => "MAX",
      }
    )
  }
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct InputClause {
  /// The subject of this input clause, text representation of unary tests.
  pub input_expression: String,
  /// Optional unary tests that constrain the result of input expression of this input clause.
  pub input_values: Option<String>,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct OutputClause {
  /// Type reference may specify the type to be used as decision table's output when more than one output clause is present.
  pub type_ref: Option<String>,
  /// The name of the output component when the decision table contains more than one output clause.
  pub name: Option<String>,
  /// Unary tests that constrain the result of output entries corresponding to this output clause.
  pub output_values: Option<String>,
  /// Default output expression, selected in incomplete table when no rules match for the decision table.
  pub default_output_entry: Option<String>,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct RuleAnnotationClause {
  /// Name that is used as the name of the rule annotation column of the containing decision table.
  pub name: String,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct DecisionRule {
  /// Ordered list of input entries that compose this decision rule.
  pub input_entries: Vec<InputEntry>,
  /// Ordered list of output entries that compose this decision rule.
  pub output_entries: Vec<OutputEntry>,
  /// Ordered list of rule annotations that compose this decision rule.
  pub annotation_entries: Vec<AnnotationEntry>,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct InputEntry {
  /// Text representation of unary test that composes this input entry.
  pub text: String,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct OutputEntry {
  /// Text representation of literal expression that composes this output entry.
  pub text: String,
}

///
#[derive(Debug, Clone, PartialEq)]
pub struct AnnotationEntry {
  /// Text representing this rule annotation.
  pub text: String,
}

/// [Dmndi] is a container for the shared [DmnStyle](DmnStyle)s
/// and all [DmnDiagram](DmnDiagram)s defined in [Definitions].
#[derive(Debug, Clone)]
pub struct Dmndi {
  /// A list of shared [DmnStyle] that can be referenced
  /// by all [DmnDiagram] and [DmnDiagramElement].
  pub styles: Vec<DmnStyle>,
  /// A list of [DmnDiagram].
  pub diagrams: Vec<DmnDiagram>,
}

/// Defines possible elements of [DmnDiagramElement].
#[derive(Debug, Clone)]
pub enum DmnDiagramElement {
  DmnShape(DmnShape),
  DmnEdge(DmnEdge),
}

/// [DmnDiagram] is the container of [DmnDiagramElement] ([DmnShape] (s) and [DmnEdge] (s)).
/// [DmnDiagram] cannot include other [DmnDiagrams](DmnDiagram).
#[derive(Debug, Clone)]
pub struct DmnDiagram {
  /// [DmnDiagram] id.
  pub id: Option<String>,
  /// The name of the diagram. Default is empty [String].
  pub name: String,
  /// The documentation of the diagram. Default is empty [String].
  pub documentation: String,
  /// The resolution of the diagram expressed in user units per inch. Default is 300.
  pub resolution: f64,
  /// A list of [DmnDiagramElement] ([DmnShape] and [DmnEdge]) that are depicted in this diagram.
  pub diagram_elements: Vec<DmnDiagramElement>,
  /// A reference to a [DmnStyle] defined in the [Dmndi] that serves as the default styling
  /// of the [DmnDiagramElement] in this [DmnDiagram].
  pub shared_style: Option<String>,
  /// A [DmnStyle] that defines the default styling for this diagram.
  /// Properties defined in that style override the ones in the 'sharedStyle'.
  pub local_style: Option<DmnStyle>,
  /// The size of this diagram. If not specified, the [DmnDiagram] is unbounded.
  pub size: Option<DcDimension>,
}

/// [DmnShape] represents a [Decision], a [BusinessKnowledgeModel], an [InputData] element,
/// a [KnowledgeSource], a [DecisionService] or a [TextAnnotation] that is depicted on the diagram.
#[derive(Debug, Clone)]
pub struct DmnShape {
  /// [DmnShape] id.
  pub id: Option<String>,
  /// The [DcBounds] of the shape relative to the origin of its parent [DmnDiagram]. The [DcBounds] MUST be specified.
  pub bounds: DcBounds,
  /// A  reference  to  a  [Decision], a [BusinessKnowledgeModel], an [InputData] element,
  /// a [KnowledgeSource], a [DecisionService] or a [TextAnnotation] MUST be specified.
  pub dmn_element_ref: Option<String>,
  /// If the [DmnShape] depicts an [InputData] element then this attribute is used to determine
  /// if the [InputData] is listed on the [Decision] element (true) or drawn as separate notational elements in the DRD (false).
  pub is_listed_input_data: bool,
  /// If the [DmnShape] depicts a [DecisionService], this attribute references a [DmnDecisionServiceDividerLine] that defines,
  /// where the [DmnShape] is divided into two parts by a straight solid line.
  /// This can be the case when a [DmnShape] depicts a [DecisionService],
  /// where the set of output decisions is smaller than the set of encapsulated decisions.
  /// The start and end waypoints of the `decisionServiceDividerLine` **MUST** be on the border of the [DmnShape].
  pub decision_service_divider_line: Option<DmnDecisionServiceDividerLine>,
  /// If the [DmnShape] depicts a [DecisionService], this attribute indicates
  /// if it should be depicted expanded (`false`) or collapsed (`true`).
  /// Default is `false`.
  pub is_collapsed: bool,
  /// A reference to a [DmnStyle] defined in the [Dmndi].
  pub shared_style: Option<String>,
  /// A [DmnStyle] that defines the styling for this element.
  pub local_style: Option<DmnStyle>,
  /// An optional label when this [DmnElement] has a visible text label.
  pub label: Option<DmnLabel>,
}

/// Struct defines line inside [DecisionService].
#[derive(Debug, Clone)]
pub struct DmnDecisionServiceDividerLine {
  pub id: Option<String>,
  /// A list of points relative to the origin of its parent [DmnDiagram] that specifies
  /// the connected line segments of the edge. At least two (2) waypoint`s MUST be specified.
  /// Waypoint must be on the border of the [DmnShape].
  pub way_points: Vec<DcPoint>,
  /// A reference to a [DmnStyle] defined in the [Dmndi].
  pub shared_style: Option<String>,
  /// A [DmnStyle] that defines the styling for this element.
  pub local_style: Option<DmnStyle>,
}

#[derive(Debug, Clone)]
pub struct DmnEdge {
  pub id: Option<String>,
  /// A list of points relative to the origin of its parent [DmnDiagram] that specifies
  /// the connected line segments of the edge. At least two (2) waypoints MUST be specified.
  pub way_points: Vec<DcPoint>,
  /// A reference to a [InformationRequirement], [KnowledgeRequirement],
  /// [AuthorityRequirement] or an [Association] MUST be specified.
  pub dmn_element_ref: Option<String>,
  /// The actual [DmnDiagramElement] this [DmnEdge] is connecting from.
  /// MUST be specified when the [DmnEdge] has a source.
  pub source_element: Option<String>,
  /// The actual [DmnDiagramElement] this [DmnEdge] is connecting to.
  /// MUST be specified when the [DmnEdge] has a target.
  pub target_element: Option<String>,
  /// A reference to a [DmnStyle] defined in the [Dmndi].
  pub shared_style: Option<String>,
  /// A [DmnStyle] that defines the styling for this element.
  pub local_style: Option<DmnStyle>,
  /// An optional label when this [DmnElement] has a visible text label.
  pub label: Option<DmnLabel>,
}

//FIXME verify this struct
/// tdb
#[derive(Debug, Clone)]
pub struct Association {}

//FIXME verify this struct
/// tdb
#[derive(Debug, Clone)]
pub struct TextAnnotation {}

/// [DmnStyle] is used to keep some non-normative visual attributes such as colors and font.
#[derive(Debug, Clone)]
pub struct DmnStyle {
  /// A unique id for this style so it can be referenced.
  /// Only styles defined in the [Dmndi] can be referenced by [DmnDiagramElement] and [DmnDiagram].
  pub id: Option<String>,
  /// The color use to fill the shape. Does not apply to [DmnEdge].
  /// Default is `white`.
  pub fill_color: Option<DcColor>,
  /// The color use to draw the shape borders.
  /// Default is `black`.
  pub stroke_color: Option<DcColor>,
  /// The color use to draw the label.
  /// Default is `black`.
  pub font_color: Option<DcColor>,
  /// A comma-separated list of Font Name that can be used to display the text.
  /// Default is `Arial`.
  pub font_family: String,
  /// The size in points of the font to use to display the text.
  /// Default is `8`.
  pub font_size: f64,
  /// If the text should be displayed in Italic.
  /// Default is `false`.
  pub font_italic: bool,
  /// If the text should be displayed in Bold.
  /// Default is `false`.
  pub font_bold: bool,
  /// If the text should be underlined.
  /// Default is `false`.
  pub font_underline: bool,
  /// If the text should be stroke through.
  /// Default is `false`.
  pub font_strike_through: bool,
  /// How text should be positioned horizontally within the Label bounds.
  /// Default depends of the [DmnDiagramElement] the label is attached to (see 13.5).
  pub label_horizontal_alignment: Option<DcAlignmentKind>,
  /// How  the  text  should  be  positioned  vertically  inside  the  Label  bounds.
  /// Default depends of the [DmnDiagramElement] the label is attached to (see 13.5).
  /// Start means `top` and end means `bottom`.
  pub label_vertical_alignment: Option<DcAlignmentKind>,
}

/// Struct represents the depiction of some textual information about a DMN element.
#[derive(Debug, Clone)]
pub struct DmnLabel {
  /// The bounds of the [DmnLabel]. When not specified, the label is positioned
  /// at its default position as determined in clause 13.5.
  pub bounds: Option<DcBounds>,
  /// An optional pretty printed text that MUST be displayed
  /// instead of the [DmnElement's](DmnElement) name if it is present.
  pub text: Option<String>,
  /// A reference to a [DmnStyle] defined in the [Dmndi].
  pub shared_style: Option<String>,
}

/// Defines RGB color.
#[derive(Debug, Clone)]
pub struct DcColor {
  pub red: u8,
  pub green: u8,
  pub blue: u8,
}

/// Defines point.
#[derive(Debug, Clone)]
pub struct DcPoint {
  pub x: f64,
  pub y: f64,
}

/// Defines bounds.
#[derive(Debug, Clone)]
pub struct DcBounds {
  pub x: f64,
  pub y: f64,
  pub width: f64,
  pub height: f64,
}

/// Defines dimensions.
#[derive(Debug, Clone)]
pub struct DcDimension {
  pub width: f64,
  pub height: f64,
}

/// Defines element kind alignment.
#[derive(Debug, Clone)]
pub enum DcAlignmentKind {
  Start,
  End,
  Center,
}

/// Defines known colors.
#[derive(Debug, Clone)]
pub enum DcKnownColor {
  Maroon = 0x800000,
  Red = 0xFF0000,
  Orange = 0xFFA500,
  Yellow = 0xFFFF00,
  Olive = 0x808000,
  Purple = 0x800080,
  Fuchsia = 0xFF00FF,
  White = 0xFFFFFF,
  Lime = 0x00FF00,
  Green = 0x008000,
  Navy = 0x000080,
  Blue = 0x0000FF,
  Aqua = 0x00FFFF,
  Teal = 0x008080,
  Black = 0x000000,
  Silver = 0xC0C0C0,
  Gray = 0x808080,
}

mod errors {
  use dmntk_feel_parser::dmntk_feel::dmntk_common::DmntkError;

  /// Errors related to the model.
  #[derive(Debug, PartialEq)]
  pub enum ModelError {
    InvalidDecisionTableOrientation(String),
    InvalidDecisionTableHitPolicy(String),
  }

  impl From<ModelError> for DmntkError {
    fn from(e: ModelError) -> Self {
      DmntkError::new("ModelError", &format!("{}", e))
    }
  }

  impl std::fmt::Display for ModelError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      match self {
        ModelError::InvalidDecisionTableOrientation(s) => {
          write!(f, "invalid decision table orientation: {}", s)
        }
        ModelError::InvalidDecisionTableHitPolicy(s) => {
          write!(f, "invalid decision table hit policy: {}", s)
        }
      }
    }
  }

  pub fn invalid_decision_table_orientation(orientation: &str) -> DmntkError {
    ModelError::InvalidDecisionTableOrientation(orientation.to_owned()).into()
  }

  pub fn invalid_decision_table_hit_policy(hit_policy: &str) -> DmntkError {
    ModelError::InvalidDecisionTableHitPolicy(hit_policy.to_owned()).into()
  }
}