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.BPOWEB_DB_NAME,
  REDIS_DB: process.env.BPOWEB_REDIS_DB,
  APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev",
};
var settings = {
  env: ENVINPUT.APP_ENV,
  salt: "%iatpD1gcxz7iF#B",
  wxconfig: {
    appId: "wx76a324c5d201d1a4",
    appname: "工具箱",
    secret: "f99d413b767f09b5dff0b3610366cc46",
  },
  basepath: path.normalize(path.join(__dirname, '../..')),
  port: process.env.NODE_PORT || 3001,
  reqEsAddr: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.reqEsDevUrl;
    } else {
      return "http://43.247.184.94:7200/";
    }
  },
  localPath: function () {
    var os = require("os");
    let platform = os.platform() || "";
    let rootPath = "";
    // windows
    if (platform.toLocaleLowerCase().startsWith('win')) {
      rootPath = "D:/tmp/";
    } else {
      rootPath="/tmp/"
    }
    return rootPath;
  },
  apiconfig: {
    AES: {
      key: "qUPsMflPfgpPP1Ua", //密钥
      iv: '1012133205963708', //偏移向量
      padding: 'PKCS7Padding' //补全值
    },
    settleApiConfig: function () {
      let domain;
      if (settings.env == "dev") {
        domain = "http://39.106.185.66:8000";
      } else {
        // domain = "http://39.106.185.66:8000";
        domain = "http://payadmin.gongsibao.com";
      }
      return {
        createMerchantApi: domain + "/merchant/busi/reg"
      }
    },
    payDomain: function () {
      if (settings.env == "dev") {
        return "http://39.106.185.66:8000";
      } else {
        // return "https://pay.gongsibao.com";
        return "http://39.106.185.66:8000";
      }
    },
    opLogUrl: function () {
      return settings.reqEsAddr() + "bigdata_zc_op_log/_doc?pretty";
    },
    opLogEsIsAdd: function () {
      return 1;
    },
    yunzhanghuDealer_id: function () {
      //商户平台ID(dealer_id)——自己
      return "27403253";
    },
    //e签宝签署状态变化完成后跳转boss页面Url地址（拒签、签署完成），在合同模板创建合同 5.4.2指定redirectUrl
    eSignBaoRedirectBossUrl: function () {
      return "https://bpohhr.gongsibao.com/h5";
    },

    //e签宝接口Url
    eSignBaoUrl: function () {
      if (settings.env == "dev") {
        // return "https://smlo.tsign.cn/opentreaty-service";
        return "https://o.tsign.cn/opentreaty-service";
      } else {
        return "https://o.tsign.cn/opentreaty-service";
      }
    },
    //e签宝银行验证接口Url
    eSignBaoBankVerifyUrl: function () {
      if (settings.env == "dev") {
        // return "https://smlo.tsign.cn/openrealname-service";
        return "https://o.tsign.cn/openrealname-service";
      } else {
        return "https://o.tsign.cn/openrealname-service";
      }
    },
    //e签宝appId
    eSignBaoAppId: function () {
      if (settings.env == "dev") {
        // return "4438757581";
        return "5111588557";
      } else {
        // return "5111566617"
        return "5111588557"
      }
    },

    //有赞商户创建  代征主体  //代征主体 67731101  测试 67731504
    getmainId: function () {
      if (settings.env == "dev") {
        return "67731504";
      } else {
        return "67731101"
      }
    },

    //e签宝appKey
    eSignBaoAppKey: function () {
      if (settings.env == "dev") {
        // return "0d798cdf01ecb31bf9949f319f8d77db";
        return "1595787e8d5b7d19f7b6798f16f41fc2";
      } else {
        // return "ea386dfd9063b3669b38b78ed36792cc"
        return "1595787e8d5b7d19f7b6798f16f41fc2"
      }
    },
    // e签宝企业accountId
    companyAccountId: function () {
      return "5c25eb4ee3b448da90babec3ce8d1144";
    },

    sign3rdHomePage: function () {
      if (settings.env == "dev") {
        return "http://127.0.0.1:3333/h5";
      } else {
        return "https://bpohhr.gongsibao.com/h5";
      }
    },

    lbwConfig: function () {
      let domain = "https://99num.com";
      return {
        validate_bank: `https://99num.com/dsp-simple/api/validate/bank`,
        validate_idcard : `https://99num.com/dsp-simple/api/validate/idcard`,
        puk: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvuoB1YqsDa1oUlPWZEUe\n" +
          "jK1y7Ja4W3AjTLfiqbo9Z6rY7h8ui/CbiZxpJuDg3H0cTI0k8UJWNO+CbYVioLo3\n" +
          "bK0Hj10jYkPdzRlQsaQ6gnJaj4DMVjmAjUUsBPnimnGsKvxLwPZTUiOMsVCOWYVH\n" +
          "rEdCrB4GVQSI9XVQFECYZTCzbtTilFB40NUlnKZ0IBbScA+c1A7buMUoR6E3hr93\n" +
          "8Mnls+szyO3J9/qA4XIq4tQIp6/UklYXn2ZkIRpk+Jb3Rm57wzfAw8VxCSVFHLxd\n" +
          "z5RXFLDeyvZuqSiA/9WX41IlSWjrcuqgHhWngnsv44LF/AsDJg/LRzLxWGK2k3Xa\n" +
          "qwIDAQAB",
        pik: "-----BEGIN PRIVATE KEY-----\n" +
          "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC2QU3cR9G5TC7M\n" +
          "pfDCQS0NDxh+a19tOY4N7SFjfeX2qqTtILcAStRg3INu0ORvba/mRoN8KAbFDKwA\n" +
          "oL3GAzF5H/4gEb1Y2+b4v/bZXP/68VbjmW93YXfRPM0LXqDSAPIUIj3tl01YyAYW\n" +
          "RE+G1AvjHmgCuYGNDZ5XGrTPNH8e+He6MQ4YaN53X2tjwf/Ob1BCLk4nTmewNQu0\n" +
          "TUBSA3ba64ZtcDOo/di456NV5pg65j0hCH/lNpz/4SH8ChtJdPU+jIBEtjTVkyfq\n" +
          "Q5i6j6IshrdZ+SV3a/q6FRMAxK6AzX15U3cbl+WKs6o+hJpO8ft19Bb+ecFcv7Sq\n" +
          "RVnZij//AgMBAAECggEAUPWBWLCugNlOkKnF4QSCtqJWBxI7OZGvgJAtnLx4QrJa\n" +
          "wNsfb4nN/Zj26Wrxjm3zDR+VmLlPCIkwfrboleUlPODxSd2Xdrl4SFc9mCCvtREv\n" +
          "v7qQwT8SsmeHzd0jIyY4YqkzSS9EtINl8M43ZXUcMq93FH7DBZ1fEOJUHxb6wQ5u\n" +
          "doNJC/iI5u1eT+tCvDdVbAgnuV4vVIw2ixiPUxpw4axsV9KVFJRSrzCelyhymIsb\n" +
          "57ei3XKlaQhZB2ZWp5BY9W70RTOYwNKMWxiswYywg3JNheIP6di+xAbX3+Td0moW\n" +
          "lbVndfkYbZ8d+psjBIbVrhwPKKbyXUwJ0BJWB+gSgQKBgQDacmkmBDkbXIawuQiK\n" +
          "nmadBf045q7KehQR3dMSLdyzLT9sQn6QwUYLU47ZspudKDtOitnGB+/R1NjciiL5\n" +
          "4eZmf81A1pEPw46PTzKVB/v8rgpEP9NRsJCwgt6BoegMUn61tfXDSqm713eDRTL9\n" +
          "jvSm0/FMahfLb9HwGM8zoROcxwKBgQDVliJhFe5vdvLaWQkRygJ+uaUyOQtP8bfq\n" +
          "7g1UPPgWg2qN7MPLyQiRx4ZksGLiTSXc53mN/gK9svdej86Gg7SKnTD8s+62cWHV\n" +
          "Vm6UdMwwXJ+dl19kYURQyVlbNoKbXQUvvaH3QEmzdGrVEpB0cWS5ZkTxgvPohZmj\n" +
          "Zc8ESulbCQKBgBas97NFjvQDJ8wiePuCs94q5/1HHO/RulGceDOT5SwIT2Qahu7Z\n" +
          "0T6Nvu9kNfkbWwStLyv6WO+sK5LBGB5eT79mFtVbMJW1VBAWRYbo3ER/gHtTMMlz\n" +
          "DaH1A8nrF55n1dVg/RD3qCTimfpbbY6aj1Td/VdUUAIDKoTE3oVafCGzAoGAM4nE\n" +
          "xfSK0m67byCo5Zf/PiEB0bqeFi5XmOLUaI1Ft/kCDzkgjd32qWah8U32rnC7QDDC\n" +
          "zhaLBsdWlYTR6veA6ym/Fls8sN1vJBF1IXGFi+3tvhM2u3wVBgFwBGiE34R0qe5y\n" +
          "VL04i4r99GhEXzS1f19EJ5rXzDXguuLoLzr8UDECgYAvXYy6LnWONt9mCPWeKkSb\n" +
          "axNhQ4MQeeCjnjnOve5iCa+kvEEDozlRioLio/C4RQKdsTv+nV0bQaAggj9y1SkT\n" +
          "xFx0Y4CxgcrySQXw9deldqCtGyqFPhYvNxrIoQ4Rrh1sXNTUtcWqMPde/9zmapyB\n" +
          "gbUgyyQCj1HTT5e9Ofxrqg==\n" +
          "-----END PRIVATE KEY-----"
      };
    }
  },
  reqEsDevUrl: "http://192.168.4.249:9200/",
  domain: function () {
    if (this.env == "dev") {
      var localsettings = require("./localsettings");
      return localsettings.reqHomePageDevUrl;
    } else {
      return "https://bpohhr.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超时时间
        },
      };
    }
  },
  settleDB: function () {
    return {
      dbname: "smart_account",
      user: "wangkun",
      password: "$zdZ7Q5PKMm6#Hy",
      config: {
        host: 'rm-2ze3yx851i59uvgg5jo.mysql.rds.aliyuncs.com',
        port: 3306,
        dialect: 'mysql',
        operatorsAliases: false,
        pool: {
          max: 5,
          min: 0,
          acquire: 90000000,
          idle: 1000000
        },
        logging: true,
        debug: true,
        dialectOptions: {
          requestTimeout: 999999,
          // instanceName:'DEV'
        } //设置MSSQL超时时间
      },
    };
  }
};
settings.ENVINPUT = ENVINPUT;
module.exports = settings;
