var fs = require('fs');
var inquirer = require("inquirer");
var mit = require("./licenses/mit")
var isc = require("./licenses/isc")
var bsd3 = require("./licenses/bsd3")
var apache2 = require("./licenses/apache2")
var unlicense = require("./licenses/unlicense")

module.exports = makeLicense

function makeLicense (args) {

  if (args.license === 'MIT') {
    var questions = copyrightQuestions();
    inquirer.prompt(questions).then(function(answers){
      var license = "The MIT License (MIT)\n\n"
      license += "Copyright (c) "+ answers.years + " " + answers.name;
      license += mit;
      print(license);
    });
  }
  else if (args.license === 'ISC'){
    var questions = copyrightQuestions();
      inquirer.prompt(questions).then(function(answers){
        var license = "Copyright (c) "
        license += answers.years + ", " + answers.name;
        license += isc;
        print(license);
    });
  }
  else if (args.license === 'BSD 2'){
    var questions = copyrightQuestions();
      inquirer.prompt(questions).then(function(answers){
        var license = "Copyright (c) "
        license += answers.years + ", " + answers.name;
        license += bsd2;
        print(license);
    });
  }
  else if (args.license === 'BSD 3'){
    var questions = copyrightQuestions();
      inquirer.prompt(questions).then(function(answers){
        var license = "Copyright (c) "
        license += answers.years + ", " + answers.name;
        license += bsd3;
        print(license);
    });
  }
  else if (args.license === 'Apache 2.0'){
    var questions = copyrightQuestions();
      inquirer.prompt(questions).then(function(answers){
        var license = "Copyright (c) "
        license += answers.years + ", " + answers.name;
        license += apache2;
        print(license);
    });
  }
  else if (args.license === 'NO LICENSE'){
    var questions = copyrightQuestions();
      inquirer.prompt(questions).then(function(answers){
        var license = "Copyright (c) "
        license += answers.years + ", " + answers.name;
        print(license);
    });
  }
  else if (args.license === 'UNLICENSE') {
    var questions = unlicenseQuestions();
    var filename=''
      inquirer.prompt(questions).then(function(answers){
        filename = answers.filename;
        print(unlicense, filename);
      })
  }
  else{
    throw Error('License Not Found');
  }
}

function copyrightQuestions() {
   var questions = [
      {
        type: "input",
        name: "name",
        message: "Full Name"
      },
      {
        type: "input",
        name: "years",
        message: "Year(s)"
      }
    ];

    return questions;
}

function unlicenseQuestions() {
   var questions = [
      {
        type: "input",
        name: "filename",
        message: "File name",
        default: "UNLICENSE"
      }
    ];
    return questions;
}

function print(license, filename) {
    if (!filename) {
      var filename = "LICENSE";
    }
    var stream = fs.createWriteStream(filename);
    stream.once('open', function(fd) {
      stream.write(license);
      stream.end();
    });
};

@@ -88,16 +88,17 @@
 es/mit%22)
+;
 %0Avar isc
@@ -125,16 +125,56 @@
 es/isc%22)
+;%0Avar bsd2 = require(%22./licenses/bsd2%22);
 %0Avar bsd
@@ -203,16 +203,17 @@
 s/bsd3%22)
+;
 %0Avar apa
@@ -248,16 +248,17 @@
 pache2%22)
+;
 %0Avar unl
@@ -297,16 +297,17 @@
 icense%22)
+;
 %0A%0Amodule

Fix missing require for bsd2 license, add semicolons