/**
 * Generate Favicons based on passed PNG (src)
 */
module.exports = function(gulp, projectPath, themePath, config) {
    var TASK_NAME = 'favicon',
        DEFAULT_CONFIG = {
            html: false,
            pipeHTML: false,
            icons: {
                android: false,
                appleIcon: false,
                favicons: true,
                firefox: false,
                windows: false,
                appleStartup: false,
                yandex: false,
                coast: false
            }
        };

    return {
        name: TASK_NAME,
        task: function getFavIconsTask(done) {
            var _subTasks = [],
                favicons = require('favicons').stream,
                gutil = require('gulp-util'),
                merge = require('merge-stream');

            _subTasks.push(
                gulp.src(
                    themePath + config.src,
                    {
                        cwd: projectPath,
                        allowEmpty: true
                    })
                .pipe( favicons(DEFAULT_CONFIG) )
                .on('error', gutil.log)
                .pipe(gulp.dest(
                    themePath + config.dest,
                    { cwd: projectPath }
                ))
            );

            return merge(_subTasks);
        },
        setProjectPath: function (path) {
            projectPath = path;
        },
        setThemePath: function (path) {
            themePath = path;
        }
    }
};

