@startuml

'++++++++++++++++++++++++++++++++++
'         Event Storming
'----------------------------------

'Version
'##################################
!function ESVersion()
  !return "0.0.1"
!end function

'Colors
'##################################
!global $ARROW_FONT_COLOR = "#263238"

!global $GROUP_FONT_COLOR = "#263238"
!global $GROUP_BORDER_COLOR = "#263238"
!global $GROUP_BG_COLOR = "#EF5350"

!global $BOUNDARY_FONT_COLOR = "#263238"
!global $BOUNDARY_BORDER_COLOR = "#263238"

!global $LEGEND_FONT_COLOR = "#FFFFFF"
!global $LEGEND_TITLE_FONT_COLOR = "#000000"
!global $LEGEND_BACKGROUND_COLOR = "transparent"

!global $BORDER_COLOR = "transparent"
!global $ARROW_COLOR = "#263238"

!global $ISSUE_FONT_COLOR = "#FFFFFF"
!global $SYSTEM_FONT_COLOR = "#FFFFFF"
!global $EVENT_FONT_COLOR = "#FFFFFF"
!global $AGGREGATE_FONT_COLOR = "#000000"
!global $READ_MODEL_FONT_COLOR = "#FFFFFF"
!global $COMMAND_FONT_COLOR = "#FFFFFF"
!global $POLICY_FONT_COLOR = "#FFFFFF"

!global $ISSUE_BG_COLOR = "#EF5350"
!global $SYSTEM_BG_COLOR = "#F06292"
!global $EVENT_BG_COLOR = "#FF9800"
!global $AGGREGATE_BG_COLOR = "#FFEB3B"
!global $READ_MODEL_BG_COLOR = "#4CAF50"
!global $COMMAND_BG_COLOR = "#03A9F4"
!global $POLICY_BG_COLOR = "#673AB7"

'Styling
'##################################
top to bottom direction
hide circle 
hide members
hide stereotype

skinparam MinClassWidth 100
skinparam shadowing false
skinparam nodesep 50
skinparam ranksep 50
skinparam defaultTextAlignment center

skinparam wrapWidth 500

' strangely setting the legend font color to white also
' turns the borders white - which is what I want...
skinparam LegendFontColor $LEGEND_FONT_COLOR
skinparam LegendBorderColor $BORDER_COLOR
skinparam LegendBackgroundColor $LEGEND_BACKGROUND_COLOR
skinparam BorderColor $BORDER_COLOR

skinparam class {
    StereotypeFontSize 12
}

skinparam Arrow {
    Color $ARROW_COLOR
    FontColor $ARROW_FONT_COLOR
    FontSize 12
}

skinparam rectangle<<group>> {
    StereotypeFontColor $GROUP_FONT_COLOR
    FontColor $GROUP_FONT_COLOR
    BackgroundColor $GROUP_BG_COLOR
    BorderColor $GROUP_BORDER_COLOR
}

skinparam rectangle<<boundary>> {
    FontColor $BOUNDARY_FONT_COLOR
    BorderColor $BOUNDARY_BORDER_COLOR
    BorderStyle dashed
}

skinparam class<<issue>> {
    FontColor $ISSUE_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $ISSUE_BG_COLOR
}

skinparam class<<system>> {
    FontColor $SYSTEM_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $SYSTEM_BG_COLOR
}

skinparam class<<event>> {
    FontColor $EVENT_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $EVENT_BG_COLOR
}

skinparam class<<aggregate>> {
    FontColor $AGGREGATE_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $AGGREGATE_BG_COLOR
}

skinparam class<<readmodel>> {
    FontColor $READ_MODEL_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $READ_MODEL_BG_COLOR
}

skinparam class<<command>> {
    FontColor $COMMAND_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $COMMAND_BG_COLOR
}

skinparam class<<policy>> {
    FontColor $POLICY_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $POLICY_BG_COLOR
}

skinparam shadowing<<legendArea>> false

' #00000000 is transparent
skinparam rectangle<<legendArea>> {
    backgroundcolor #00000000
    bordercolor #00000000
}

' Layout
' ##################################
!procedure HIDE_STEREOTYPE()
hide stereotype
!endprocedure

!procedure $getHideStereotype($hideStereotype)
!if ($hideStereotype == "true")
hide stereotype
!endif
!endprocedure

!procedure $getLegendTable()
<#037777777777,#00000000>|<color:$LEGEND_TITLE_COLOR>**Legend**</color> |
$showActiveLegendEntries($tagDefaultLegend)
$showActiveLegendEntries($tagCustomLegend)
!endprocedure

!procedure $getLegendArea($areaAlias, $hideStereotype)
$getHideStereotype($hideStereotype)
rectangle $areaAlias<<legendArea>> [
$getLegendTable()
]
!endprocedure

!procedure LAYOUT_TOP_DOWN()
!global $fix_direction=%false()
top to bottom direction
!endprocedure

!procedure LAYOUT_LEFT_RIGHT() 
!global $fix_direction = %false()
left to right direction
!endprocedure

!procedure LAYOUT_LANDSCAPE() 
!global $fix_direction = %true()
left to right direction
!endprocedure

allow_mixing

!procedure LAYOUT_WITH_LEGEND()
legend bottom right
|<color:$LEGEND_TITLE_FONT_COLOR>**Legend**</color> |
|<$COMMAND_BG_COLOR> <color:$COMMAND_FONT_COLOR>command</color> |
|<$EVENT_BG_COLOR> <color:$EVENT_FONT_COLOR>event</color> |
|<$AGGREGATE_BG_COLOR> <color:$AGGREGATE_FONT_COLOR>aggregate*</color> |
|<$READ_MODEL_BG_COLOR> <color:$READ_MODEL_FONT_COLOR>read model</color> |
|<$ISSUE_BG_COLOR> <color:$ISSUE_FONT_COLOR>issue</color> |
|<$POLICY_BG_COLOR> <color:$POLICY_FONT_COLOR>policy</color> |
|<$SYSTEM_BG_COLOR> <color:$SYSTEM_FONT_COLOR>system</color> |
endlegend
!endprocedure

!unquoted procedure BoundedContext($alias, $label)
rectangle "==$label\n<size:10>BoundedContext</size>" as $alias
!endprocedure

' Groups
' ##################################

!unquoted procedure Group($alias)
rectangle "Group" <<group>> as $alias   
!endprocedure

' Elements
' ##################################

!unquoted procedure Issue($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<issue>> 
!endprocedure

!unquoted procedure System($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<system>> 
!endprocedure

!unquoted procedure Event($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<event>> 
!endprocedure

!unquoted procedure Aggregate($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<aggregate>> 
!endprocedure

!unquoted procedure ReadModel($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias  <<readmodel>> 
!endprocedure

!unquoted procedure Command($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<command>>
!endprocedure

!unquoted procedure Policy($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<policy>> 
!endprocedure

!unquoted procedure Actor($alias, $label, $descr="")
actor "$label\n\n$descr" as $alias <<actor>>
!endprocedure


' Relationship
' ##################################
!unquoted procedure Label_($label="")
!if ($label != "")
: $label
!endif
!endprocedure

!unquoted procedure Rel_($alias1, $alias2, $label, $direction="")
$alias1 $direction $alias2 Label_($label)
!endprocedure

!unquoted procedure Rel($from, $to, $label="")
Rel_($from, $to, $label, "-->") 
!endprocedure

!unquoted procedure Rel_Back($from, $to, $label="")
Rel_($from, $to, $label, "<--")
!endprocedure

!unquoted procedure Rel_Neighbor($from, $to, $label="")
Rel_($from, $to, $label, "->")
!endproceduren

!unquoted procedure Rel_Back_Neighbor($from, $to, $label="")
Rel_($from, $to, $label, "<-")
!endprocedure

!unquoted procedure Rel_D($from, $to, $label="")
Rel_($from, $to, $label, "-down->")
!endprocedure

!unquoted procedure Rel_Down($from, $to, $label="")
Rel_($from, $to, $label, "-down->")
!endprocedure

!unquoted procedure Rel_U($from, $to, $label="")
Rel_($from, $to, $label, "-up->")
!endprocedure

!unquoted procedure Rel_Up($from, $to, $label="")
Rel_($from, $to, $label, "-up->")
!endprocedure

!unquoted procedure Rel_L($from, $to, $label="")
Rel_($from, $to, $label, "-left->")
!endprocedure

!unquoted procedure Rel_Left($from, $to, $label="")
Rel_($from, $to, $label, "-left->")
!endprocedure

!unquoted procedure Rel_R($from, $to, $label="")
Rel_($from, $to, $label, "-right->")
!endprocedure

!unquoted procedure Rel_Right($from, $to, $label="")
Rel_($from, $to, $label, "-right->")
!endprocedure

'Testing Area
HIDE_STEREOTYPE()
LAYOUT_WITH_LEGEND()
LAYOUT_LEFT_RIGHT()
BoundedContext(accesion, "test 01"){
Issue(tt0, "Test", "test01" )
Command(tt1, "Test", "test01" )
Event(tt2, "Test", "test01" )
Aggregate(tt3, "Test", "test01" )
}

Actor(j, "Archivist", "Working at archives")
Rel(j, tt1, "Trigger the command")
Rel(tt1, tt2)
Rel(tt2, tt3)

BoundedContext(accession, "Accession"){
    Command(placeOrder, "Create x Order") 
    Command(cancelOrder, "Cancel Order")
    Command(validateOrder, "Validate Order")
    Command(changeOrder, "Change Order")
    Command(saveOrder, "Save Order")
    Command(deleteOrder, "Delete Order")
    Event(orderPlaced, "Order Placed") 
    Event(orderCancelled, "Order Cancelled")
    Event(orderValidated, "Order Validated")
}
Rel(j, placeOrder)
Rel(j, cancelOrder)
Rel(j, validateOrder)
Rel(placeOrder, orderPlaced)

@enduml
