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

'Colors
'##################################

!global $ARROW_FONT_COLOR = "#263238"

!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 $CONCERN_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 $CONCERN_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 10
skinparam ranksep 10
skinparam defaultTextAlignment center

skinparam wrapWidth 200

' 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>> {
    FontColor transparent
    BorderColor transparent
}

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

skinparam class<<concern>> {
    FontColor $CONCERN_FONT_COLOR
    BorderColor $BORDER_COLOR
    BackgroundColor $CONCERN_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
}


' Layout
' ##################################

'from c4.puml
!global $fix_direction=%false()

!function $down($start,$end)
!if ($fix_direction)
!return $start+"RIGHT"+$end
!else
!return $start+"DOWN"+$end
!endif
!endfunction

!function $up($start,$end)
!if ($fix_direction)
!return $start+"LEFT"+$end
!else
!return $start+"UP"+$end
!endif
!endfunction

!function $left($start,$end)
!if ($fix_direction)
!return $start+"UP"+$end
!else
!return $start+"LEFT"+$end
!endif
!endfunction

!function $right($start,$end)
!if ($fix_direction)
!return $start+"DOWN"+$end
!else
!return $start+"RIGHT"+$end
!endif
!endfunction

!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

!procedure LAYOUT_WITH_LEGEND()
hide stereotype
legend bottom right
|<color:$LEGEND_TITLE_FONT_COLOR>**Legend**</color> |
|<$CONCERN_BG_COLOR> <color:$CONCERN_FONT_COLOR>concern</color> |
|<$SYSTEM_BG_COLOR> <color:$SYSTEM_FONT_COLOR>system</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> |
|<$COMMAND_BG_COLOR> <color:$COMMAND_FONT_COLOR>command</color> |
|<$POLICY_BG_COLOR> <color:$POLICY_FONT_COLOR>policy</color> |
endlegend
!endprocedure

' Boundaries
' ##################################

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

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

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

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

!unquoted procedure Concern($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<concern>> 
!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="", $actor="")
!if ($actor != "") 
class "==$label\n\n $descr" as $alias< $actor > <<command>> 
!else 
class "==$label\n\n $descr" as $alias <<command>>
!endif
!endprocedure

!unquoted procedure Policy($alias, $label, $descr="")
class "==$label\n\n $descr" as $alias <<policy>> 
!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

' Layout Helpers
' ##################################

!unquoted procedure Lay_D($from, $to)
$from -[hidden]d- $to
!endprocedure

!unquoted procedure Lay_U($from, $to)
$from -[hidden]u- $to
!endprocedure

!unquoted procedure Lay_R($from, $to)
$from -[hidden]r- $to
!endprocedure

!unquoted procedure Lay_L($from, $to)
$from -[hidden]l- $to
!endprocedure
