module.exports = ((name, options)=>{

  // Default set of users in main repos.
  var users = [
      { username : `${options.username}`, password : `${options.password}` }
    , { username : `chess` }
    // , { username : `baptistdev`, password : 'encrypted' }
    // , { username : `guest`, password : 'encrypted' }
  ]

  // ${options.reposerver} should be used to lookup current config.

  // User can always add more branches and remotes as needed. Mainifest only occupies 
      // well defined namespaces
  var remotes = {
    // these are both fetch and push remotes. Use push - remotes to override push.
      'chess' : { 
          server : `${options.reposerver}`, user : 'chess', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
        , push : 'no-pushing' }
    , 'baptistdev-public' : { 
        server : `https://github.com`, user : 'baptistdev', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
      , push : 'no-pushing' }
      
        
    // Multiple urls dont tell us the current origin which may be 
    // different based on currently available/accessible based on device and client.
    // We just treat them as different remotes and merge as needed.
    // 
    , 'origin' : { 
        server : `${options.reposerver}`, user : '${options.username}', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
      }
    , 'origin-public' : { 
        server : `https://git.bbh.org.in`, user : 'chess', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
      , push : {
          server : `${options.reposerver}`, user : `${options.username}`, path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} 
        }
      }
    , 'origin-unc' : { 
        server : `//172.16.0.27/repos`, user : '${options.username}', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
      }
    // , { `${options.username}` : `https://git.bbh.org.in/${options.username}/elxr.git` }
  }

    // , 'fetch-remotes' : [] // Multiple fetch remotes are not supported by git.
      // We therefore need to use 
      // - a pullall 
      // - or branch alias for multiple remote branch tracking branch strategy.
      // 		-- This is however limited to corresponding branch names 

    // tracking branches.
    // We at least need one branch for each remote that we wish to track.
    // , 'tracking-branches' : [
    //   { master : ['origin/master', 'chess/master'] }
    // ]

  var reposerverinstances = {
      'http://git.bbh' : { users, remotes }
    , 'https://git.bbh.org.in' : { users, remotes, external : true }
    , '//172.16.0.27/repos' : { users, remotes }
    , 'https://github.com' : {
          // We host a miniaml set of repositories in github. 
          get users() { return [{ username : `${this.username}` }]}, username : `baptistdev`
          , remotes : { 
            'baptistdev-public' : { 
              server : `https://github.com`, user : 'baptistdev', path : ``, get url(){ return `${this.server}/${this.user}/${this.path}`} // fetch
            , push : 'no-pushing' }
          // , Add other remotes here. 
          }
        , external : true, public : true 
    }
  }
  return {
      reposervers : Object.keys(reposerverinstances)
    , reposerverinstances

    , repos : [
      { repo : 'elxr' }
    ]
  }
})