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,
  REDIS_DB:process.env.JIAXIYA_REDIS_DB,
  DB_NAME:process.env.JIAXIYA_DB_NAME,
  APP_ENV:process.env.APP_ENV?process.env.APP_ENV:"dev"
};
var settings = {
  env:ENVINPUT.APP_ENV,
  appKey:"d47f72a7228243a3bad03541d2a2c22c",
  paasKey:"wx76a324c5d201d1a4",
  secret:"047c51d2f0974802a17dde560d2871cb",
  //为了直接从应用客户端登录,需要查询出当前用户所在公司
  //如果有这个配置，就表示支持从应用自己的客户端登录或注册
  companyKey:"af4dfb53282d4743866259e0b15b134e",
  salt: "%iatpD1gcxz7iF#B",
  basepath   : path.normalize(path.join(__dirname, '../..')),
  port       : process.env.NODE_PORT || 3003,
  paasUrl:function(){
    if(this.env=="dev"){
      return "http://p.apps.com:4001/";
    }else {
      return "https://open.gongsibao.com/";
    }
  },
  channelApiUrl: function () {
    if (this.env == "dev") {
      return "http://192.168.18.61:4003";
    } else {
      return "http://zc-channel-service";
    }
  },
  uploadfileossurl:function () {
    if (this.env == "dev") {
      return "http://192.168.18.15:8080";
    } else {
      return "http://localhost:8080";
    }
  },
  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;
    },
  },
  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超时时间
       },
     };
    }
  }
};
settings.ENVINPUT=ENVINPUT;
module.exports = settings;
