'use strict'

const Logger = require('../util/logger')
const Repository = require('../common/repository')

class Dot {
  constructor (config) {
    this.config = config
    this.repository = new Repository(config)
  }

  async run () {
    await this.repository.populate()
    const stmts = []
    Object.values(this.repository.issues).forEach((issue) => {
      stmts.push(`"${issue.key}"`)
      issue.links.forEach((link) => {
        stmts.push(`"${issue.key}"->"${link.key}"[label="${link.desc}"]`)
      })
    })
    const dot = `digraph{${stmts.join(';')}}`

    Logger.global.success(`dot generated:\n${dot}`)
  }
}

exports = module.exports = Dot

@@ -352,35 +352,35 @@
  =%3E %7B%0A      
-stmts.push(
+let stmt = 
 %60%22$%7Bissue.ke
@@ -383,16 +383,223 @@
 e.key%7D%22%60
+%0A      if (issue.statusCategory === 'Done') %7B%0A        stmt += %60%5Bshape=%22doublecircle%22%5D%60%0A      %7D else %7B%0A        stmt += %60%5Bshape=%22circle%22%5D%60%0A      %7D%0A      // ??? style=filled, fillcolor=red%0A      stmts.push(stmt
 )%0A      
@@ -649,31 +649,33 @@
 ts.push(%60%22$%7B
-issue.k
+link.srcK
 ey%7D%22-%3E%22$%7Blin
@@ -676,17 +676,20 @@
 %22$%7Blink.
-k
+dstK
 ey%7D%22%5Blab
@@ -703,12 +703,13 @@
 ink.
-desc
+label
 %7D%22%5D%60

generate dot dgraph