import issues from './list'

/**
 * Help Url
 *
 * Construct a link to a helpful neurostars query, based on the
 * issue key
 */
const constructHelpUrl = issue => {
  const neurostarsPrefix = 'https://neurostars.org/'
  const searchQuery = issue && issue.key ? 'search?q=' + issue.key : ''
  const helpUrl = neurostarsPrefix + searchQuery
  return helpUrl
}

/**
 * Issue
 *
 * A constructor for BIDS issues.
 *
 * @param {Object} options
 * @param {string} options.key The descriptive string matching the issue code
 * @param {number} options.code Issue code - see 'list.js' for definitions
 * @param {string} [options.file] The relative path of the affected file
 * @param {string} [options.evidence] The value throwing this issue
 * @param {number} [options.line] The line of the affected file (if within a file)
 * @param {number} [options.character] The character offset in the affected line
 * @param {string} [options.severity] Is this an error or warning?
 * @param {string} [options.reason] A descriptive
 * @param {string} [options.helpUrl] A URL providing documentation to help solve this error
 * @returns {Object} Issue object
 */
function Issue(options) {
  const code = options.hasOwnProperty('code') ? options.code : null
  const issue = issues[code]

  this.key = issue.key
  this.code = code
  this.file = options.hasOwnProperty('file') ? options.file : null
  this.evidence = options.hasOwnProperty('evidence') ? options.evidence : null
  this.line = options.hasOwnProperty('line') ? options.line : null
  this.character = options.hasOwnProperty('character')
    ? options.character
    : null
  this.severity = options.hasOwnProperty('severity')
    ? options.severity
    : issue.severity
  this.reason = options.hasOwnProperty('reason') ? options.reason : issue.reason
  this.helpUrl = constructHelpUrl(issue)
}

export default Issue

@@ -588,38 +588,36 @@
 ions%0A * @param %7B
-string
+File
 %7D %5Boptions.file%5D
@@ -621,28 +621,23 @@
 le%5D 
-The relative path of
+File object for
  the

Correct type for Issue options.file