var path = require('path');
var ENVINPUT = {
  DB_HOST: process.env.DB_HOST,
  DB_PORT: process.env.DB_PORT,
  DB_USER: process.env.DB_USER,
  DB_PWD: process.env.DB_PWD,
  REDIS_HOST: process.env.REDIS_HOST,
  REDIS_PORT: process.env.REDIS_PORT,
  REDIS_PWD: process.env.REDIS_PWD,
  DB_NAME: process.env.ESIGNSVEORDER_DB_NAME,
  REDIS_DB: process.env.ESIGNSVORDER_REDIS_DB,
  APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
};

var settings = {
  env: ENVINPUT.APP_ENV,
  appKey: "40d64e586551405c9bcafab87266bb04",
  paasKey: "wx76a324c5d201d1a4",
  secret: "f99d413b767f09b5dff0b3610366cc46",
  salt: "%iatpD1gcxz7iF#B",
  cacheprefix: "sjb",
  usertimeout: 3600, //单位秒
  basepath: path.normalize(path.join(__dirname, '../..')),
  port: process.env.NODE_PORT || 3653,
  defaultPassWord: "987456",
  paasUrl: function () {
    if (this.env == "dev") {
      return "http://p.apps.com:3001/";
    } else {
      return "http://www.telecredit.cn/";
    }
  },
  reqEsAddr: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return "http://43.247.184.94:7200/"; //localsettings.reqEsDevUrl;
    } else {
      return "http://43.247.184.94:7200/";
    }
  },
  apiconfig: {
    opLogUrl: function () {
      return settings.reqEsAddr() + "bigdata_zc_op_log/_doc?pretty";
    },
    opLogEsIsAdd: function () {
      return 1;
    }
  },
  homePage: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.reqHomePageDevUrl;
    } else {
      return "http://boss.gongsibao.com/";
    }
  },
  redis: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.redis;
    } else {
      return {
        host: ENVINPUT.REDIS_HOST,
        port: ENVINPUT.REDIS_PORT,
        password: ENVINPUT.REDIS_PWD,
        db: ENVINPUT.REDIS_DB,
      };
    }
  },
  database: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.database;
    } else {
      return {
        dbname: ENVINPUT.DB_NAME,
        user: ENVINPUT.DB_USER,
        password: ENVINPUT.DB_PWD,
        config: {
          host: ENVINPUT.DB_HOST,
          dialect: 'mysql',
          operatorsAliases: false,
          pool: {
            max: 5,
            min: 0,
            acquire: 90000000,
            idle: 1000000
          },
          debug: false,
          dialectOptions: {
            requestTimeout: 999999,
            // instanceName:'DEV'
          } //设置MSSQL超时时间
        },
      };
    }
  },
  //阿里短信配置
  aliSmsConfig:function(){
    return {
      accessKeyId: 'LTAIurdHMmfgXJjr',
      accessKeySecret: 'OBP8jxN5ZTgZnEIFgXHkvBB0QEN4E2',
      endpoint: 'https://dysmsapi.aliyuncs.com',
      apiVersion: '2017-05-25',
      signName: "薪必果",
      template:{
        loginTemplate:{
          order:"125944682",
          code:"SMS_181196624"
        },
        authenticationTemplate:{
          order:"125949710",
          code:"SMS_181201598"
        },
        smsTemplate:{
          order:"125939639",
          code:"SMS_181191611"
        }
      }
    }
  }
};
module.exports = settings;