/*global brackets, define */

define(function (require, exports, module) {
    "use strict";

    var _                   = brackets.getModule("thirdparty/lodash"),
        PreferencesManager  = brackets.getModule("preferences/PreferencesManager"),
        prefs               = PreferencesManager.getExtensionPrefs("brackets-git");

    var defaultPreferences = {
        // features
        "stripWhitespaceFromCommits": {     "type": "boolean",           "value": true          },
        "addEndlineToTheEndOfFile": {       "type": "boolean",           "value": true          },
        "useGitGutter": {                   "type": "boolean",           "value": true          },
        "markModifiedInTree": {             "type": "boolean",           "value": true          },
        "useCodeInspection": {              "type": "boolean",           "value": true          },
        "storePlainTextPasswords": {        "type": "boolean",           "value": false         },
        // shortcuts
        "panelShortcut": {                  "type": "string",            "value": "Ctrl-Alt-G"  },
        "commitCurrentShortcut": {          "type": "string",            "value": null          },
        "commitAllShortcut": {              "type": "string",            "value": null          },
        // system
        "lastVersion": {                    "type": "string",            "value": null          },
        "panelEnabled": {                   "type": "boolean",           "value": true          },
        "TIMEOUT_VALUE": {                  "type": "number",            "value": 30000         },
        "terminalCommand": {                "type": "string",            "value": null          },
        "extensionDirectory": {             "type": "string",            "value": undefined     },
        // platform specific
        "gitIsInSystemPath": {
            "type": "boolean",
            "os": {
                "win":      { "value": true },
                "mac":      { "value": false },
                "linux":    { "value": false }
            }
        },
        "gitPath": {
            "type": "string",
            "os": {
                "win":      { "value": "C:\\Program Files (x86)\\Git\\bin\\git.exe" },
                "mac":      { "value": "/usr/local/git/bin/git" },
                "linux":    { "value": "/usr/bin/git" }
            }
        },
        "msysgitPath": {
            "type": "string",
            "os": {
                "win":      { "value": "C:\\Program Files (x86)\\Git\\" },
                "mac":      { "value": null },
                "linux":    { "value": null }
            }
        }
    };

    _.each(defaultPreferences, function (definition, key) {
        if (definition.os && definition.os[brackets.platform]) {
            prefs.definePreference(key, definition.type, definition.os[brackets.platform].value);
        } else {
            prefs.definePreference(key, definition.type, definition.value);
        }
    });
    prefs.save();

    prefs.getAll = function () {
        var obj = {};
        _.each(defaultPreferences, function (definition, key) {
            obj[key] = this.get(key);
        }, this);
        return obj;
    };

    prefs.getDefaults = function () {
        var obj = {};
        _.each(defaultPreferences, function (definition, key) {
            var defaultValue;
            if (definition.os && definition.os[brackets.platform]) {
                defaultValue = definition.os[brackets.platform].value;
            } else {
                defaultValue = definition.value;
            }
            obj[key] = defaultValue;
        }, this);
        return obj;
    };

    prefs.persist = function (key, value) {
        this.set(key, value);
        this.save();
    };

    module.exports = prefs;
});

@@ -1807,37 +1807,8 @@
  %7D,%0A
-        // platform specific%0A
     
@@ -1825,33 +1825,32 @@
 InSystemPath%22: %7B
-%0A
             %22typ
@@ -1837,32 +1837,34 @@
 %22: %7B            
+  
 %22type%22: %22boolean
@@ -1865,18 +1865,16 @@
 oolean%22,
-%0A 
         
@@ -1879,93 +1879,8 @@
     
- %22os%22: %7B%0A                %22win%22:      %7B %22value%22: true %7D,%0A                %22mac%22:      %7B
  %22va
@@ -1891,27 +1891,24 @@
 : false 
-%7D,%0A
         
         
@@ -1895,32 +1895,35 @@
 lse         
+%7D,%0A
         
 %22linux%22:    
@@ -1914,63 +1914,28 @@
     
-%22linux%22:    %7B %22value%22: false %7D%0A            %7D%0A        %7D,
+// platform specific
 %0A   

Fix #155