@startuml

!theme plain
hide empty methods

!procedure $table($name, $slug)
entity "<b>$name</b>" as $slug << (T, Orange) table >>
!endprocedure

!procedure $type($name, $slug)
entity "<b>$name</b>" as $slug << (E, Cyan) type (enum) >>
!endprocedure

!procedure $pk($name)
<color:#GoldenRod><&key></color> <b><i>$name</i></b>: 
!endprocedure

!procedure $enum_link($name)
<color:#Orange><&tag></color> <i>$name</i>: 
!endprocedure

!procedure $fk($name)
<color:#Silver><&key></color> <i>$name</i>:
!endprocedure

!procedure $column($name)
{field} <color:#grey><&chevron-right></color> <i>$name</i>:
!endprocedure

!procedure $enum_field($name)
{field} <color:#grey><&chevron-right></color> $name
!endprocedure


$table("FIELD", "field") {
    $pk("ID") INTEGER NOT NULL
    $enum_link("TYPE") VARCHAR 
    $fk("STEP_ID") INTEGER NOT NULL
    $fk("BLOCK_FIELD_ID") INTEGER NOT NULL
    $column("REQUIRED") BOOLEAN
}

$table("BLOCK_FIELD", "block_field") {
    $pk("ID") INTEGER NOT NULL
    $fk("STEP_ID") INTEGER NOT NULL
    $column("NAME") VARCHAR
    $enum_link("TYPE") VARCHAR NOT NULL
    $column("REQUIRED") BOOLEAN
    $column("FLAGS") JSON
}

$table("STEP", "step") {
    $pk("ID") INTEGER NOT NULL
    $fk("WORKFLOW_ID") INTEGER NOT NULL
    $column("NAME") VARCHAR
    $column("DESCRIPTION") TEXT
    $column("NEED_AGREEMENT") BOOLEAN
}

$table("RESPONSIBLE", "responsible") {
    $pk("ID") INTEGER NOT NULL
    $fk("STEP_ID") INTEGER NOT NULL
    $column("ASSIGNATION_TYPE") VARCHAR
    $column("EXECUTION_TYPE") VARCHAR
    $column("USERS") INTEGER[]
}

$table("WORKFLOW", "workflow") {
    $pk("ID") INTEGER NOT NULL
    $column("NAME") VARCHAR
    $column("CREATED_AT") TIMESTAMP
    $enum_link("TYPE") VARCHAR
    $enum_link("STATUS") VARCHAR
    $column("DESCRIPTION") TEXT
}

$type("FIELD_TYPE", "field_type") {
    $enum_field("select")
    $enum_field("input")
    $enum_field("datetime")
    $enum_field("multiselect")
    $enum_field("filefield")
    $enum_field("blockfield")
}

$type("BLOCK_FIELD_TYPE", "block_field_type") {
    $enum_field("allow_access_field")
    $enum_field("object")
    $enum_field("device")
}

$type("WORKFLOW_TYPE", "workflow_type") {
    $enum_field("general")
    $enum_field("access_change")
    $enum_field("object_change")
    $enum_field("custom")
}

$type("WORKFLOW_STATUS", "workflow_status") {
    $enum_field("active")
    $enum_field("inactive")
    $enum_field("draft")
}

field::TYPE -- field_type
field::BLOCK_FIELD_ID }o--|| block_field::ID
workflow::TYPE -- workflow_type
workflow::STATUS -- workflow_status
field::STEP }o--|| step::ID
block_field::STEP }o--|| step::ID
block_field::TYPE -- block_field_type
step::WORKFLOW_ID }|--|| workflow::ID
responsible::STEP_ID ||--|| step::ID

@enduml