var Model = require('base/model')
var debug = require('debug')('holodex:role:model')

module.exports = Model.extend({
  typeName: 'Role',
  collectionName: 'roles',

  props: {
    type: 'link',
    agent: 'link',
    relationship: 'link'
  },

  derived: {
    label: {
      deps: ['type', 'agent', 'relationship'],
      fn: function () {
        var agentsByRole = {}
        if (this.relationship) {
          this.relationship.roles.forEach(function (role) {
            agentsByRole[role.type.name] = role.agent.getId()
          })
        } else {
          agentsByRole[this.type.name] = this.agent
        }
        return this.type.generateLabel(agentsByRole)
      }
    },
    linkTypeId: {
      deps: ['type'],
      fn: function () {
        return this.type.getId() + '/link'
      }
    }
  }
})

@@ -79,16 +79,17 @@
 odel')%0A%0A
+%0A
 module.e
@@ -792,24 +792,365 @@
 nk'%0A      %7D%0A
+    %7D,%0A    linkTargetId: %7B%0A      cache: false,%0A      deps: %5B'relationship', 'agent'%5D,%0A      fn: function () %7B%0A        return this.relationship.roles.reduce(function (memo, role) %7B%0A          if (role.agent.getId() !== this.agent.getId()) %7B%0A            memo = role.agent.getId()%0A          %7D%0A          return memo%0A        %7D.bind(this))%0A      %7D%0A
     %7D%0A  %7D%0A%7D)

add linkTargetId to role/model