var Promise = require('bluebird')
var promisify = Promise.promisify

var path = require('path')
var stat = promisify(require('fs').stat)

var model = require('@packard/model')
var Artist = model.Artist
var Album = model.MultitrackAlbum
var Track = model.Track

var flac = require('./flac.js')

var EMPTY_TRACK = path.resolve(__dirname, '../fixtures/empty.flac')

function makeAlbum (root, date, artistName, albumName, trackNames) {
  const artist = new Artist(artistName)
  const album = new Album(albumName, artist)
  return stat(EMPTY_TRACK).then(function (stats) {
    return flac.makeAlbum(root, trackNames.map(function (trackName, index) {
      var track = new Track(
        trackName,
        album,
        artist,
        {
          path: EMPTY_TRACK, // path is irrelevant, since we're generating it
          stats: stats,
          ext: '.flac'
        }
      )
      track.date = date
      track.index = index + 1
      return track
    }))
  })
}

module.exports = { makeAlbum: makeAlbum }

@@ -314,15 +314,12 @@
 ath.
-resolve
+join
 (__d
@@ -413,19 +413,23 @@
 e, track
-Nam
+Templat
 es) %7B%0A  
@@ -599,19 +599,23 @@
 t, track
-Nam
+Templat
 es.map(f
@@ -624,23 +624,22 @@
 ction (t
-rackNam
+emplat
 e, index
@@ -684,16 +684,36 @@
    t
-rackName
+emplate.name %7C%7C '%5Buntitled%5D'
 ,%0A  
@@ -783,57 +783,8 @@
 ACK,
- // path is irrelevant, since we're generating it
 %0A   
@@ -826,16 +826,17 @@
  '.flac'
+,
 %0A       
@@ -840,36 +840,43 @@
     
-%7D%0A      )
+  index: index + 1,
 %0A      
-track.
+    
 date
- =
+:
  dat
@@ -887,31 +887,95 @@
     
-track.index = index + 1
+  %7D%0A      )%0A      track.file.path = path.join(root, template.path %7C%7C track.safeName())%0A
 %0A   

allow t