var MAGNET = window.MAGNET || {};
MAGNET.data = MAGNET.data || {};
MAGNET.data.userInfo= MAGNET.data.userInfo|| {};
MAGNET.data.userInfo.userData = MAGNET.data.userInfo.userData || {};



/**
 * Singleton to handle parsing and writing of feeds from astrology.com
 * Contains data object to store all feed data as it is received, along
 * with a public method to get an astrology report. Helpers include
 * parsing of feed data, writing, and utility date/url methods.
 *
 * @author      Justine Chen
 */

MAGNET.data.userInfo.userAccount= function() {


    /* PRIVATE MEMBERS */

 var magazines = {
       "gourmet": [
            { id:"wsert1",        level:"editor"},
            { id:"pesley",        level:"editor"},
            { id:"christy",       level:"editor"},
            { id:"jsu",           level:"editor"},
            { id:"Caroline",      level:"editor"},
            { id:"Marisa",        level:"editor"},
            { id:"andreaalbin",   level:"editor"},
            { id:"GMME",          level:"editor"},
            { id:"atouchet",      level:"editor"},
            { id:"LC",            level:"editor"},
            { id:"Doc",           level:"editor"},
            { id:"IanKnauer",     level:"editor"},
            { id:"RuthReichl",    level:"editor"},
            { id:"Shelley",       level:"editor"},
            { id:"PAULG",         level:"editor"},
            { id:"asytsma",       level:"editor"},
            { id:"KempMinifie",   level:"editor"},
            { id:"gourmetonline", level:"editor"},
            { id:"adambrent",     level:"editor"},
            { id:"katew",         level:"editor"},
            { id:"GenevieveKo",   level:"editor"},
            { id:"GenevieveKo",   level:"editor"},
            { id:"Abrams",        level:"editor"},
            { id:"spike2",        level:"editor"},
            { id:"dudleycp",      level:"editor"}
        ]
    };







    /**
     * Stores the feed data objects when they are instantiated.
     */
    var accounts = [];
    var magazineName;
    var dataReady = false;


    /**
     * Gets a the user account information from the central xml depends on the name of the magazine
     *
     *
     * @throws          typeError       The sign or type requested is not found in the XML
     * @throws          referenceError  The callback function errs while executing
     * @return                          void
     */
    function getUserAccounts() {

       if ( magazines["gourmet"] != null){
        if ( accounts.length <= 0 ){

           for ( var i = 0; i < magazines["gourmet"].length ; i++){

              var data = magazines["gourmet"][i];
              var id = data.id;
              var level = data.level;
              var user = new MAGNET.data.userInfo.userData();
              user.setUserInfo(id,level);
              accounts[id] = user;
           }
        }
       }
    }


    function isUserEditor(name){
        if ( accounts.length <= 0){
           getUserAccounts();
        }
        if ( accounts[name] != null){
           return accounts[name].isEditor();
        }
        return false;
    }

    function setMagazine(name){
         magazineName = name;
    }

    /* PUBLIC MEMBERS */

    return {
        GetUserAccounts: getUserAccounts,
        IsUserEditor: isUserEditor,
        SetMagazine: setMagazine
    };
}();



/**
 * Class to store user information from xml
 *
 *
 * @author      Justine Chen
 */



/* constructor */

MAGNET.data.userInfo.userData = function(id, level) {
        var id  = id;
        var level = level;
};

MAGNET.data.userInfo.userData.prototype = {

    /**
     * Given an astrological sign, returns the appropriate description
     *
     * @param   string  sign    The zodiac sign to look up
     * @return  string          The text description for that sign
     */
    setUserInfo: function(id, level) {
        this.id = id;
        this.level = level;
    },



    /**
     * Sets the text description given a sign
     *
     * @param   string  sign        The zodiac sign in which to store the description
     * @param   string  description The text description to store
     */
    getUserLevel: function() {
        return this.level;
    },

    getUserId: function(){
        return this.id;
    },

    isEditor: function(){
        return (this.level == 'editor');
    }
};

