import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
import defaultConfig from './config.default';

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  config.middleware = [ 'parmsDecode', 'getIp', 'proxy' ];
  config.mongoose = {
    url: 'mongodb://dbop:zyzSQ2021@dds-8vb7d5060bb271d41.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb7d5060bb271d42.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb7d5060bb271d43.mongodb.zhangbei.rds.aliyuncs.com:3717/zyz?replicaSet=mgset-508112745', // 内网
    options: { useNewUrlParser: true, useUnifiedTopology: true },
  };
  config.gmmongoose = {
    url: 'mongodb://dbop:zyzSQGm2021@dds-8vb5de93552a67941.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb5de93552a67942.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-8vb5de93552a67943.mongodb.zhangbei.rds.aliyuncs.com:3717/zyzgm?readPreference=secondary&replicaSet=mgset-508112742', // 内网
    options: { useNewUrlParser: true, useUnifiedTopology: true },
  };
  config.redis = {
    url: 'r-8vb7l1s8ne4vm6v6x6.redis.zhangbei.rds.aliyuncs.com', // 内网
    pw: 'PANl3Vr2eozkq4N2'
  };

  config.xtransit = {
    server: 'ws://172.16.4.109:9092',
    appId: 4,
    appSecret: '4ce0f5d8561939271c1d8c5714a9d9eb'
  };

  config.customLogger = {
    linkLogger: {
      file: '/zyz_logs/web-server/link-log.log',
      formatter(meta) {
        return `[${meta.level}] [${meta.date}] ${meta.message}`;
      },
    },
  };

  config.logrotator = {
    filesRotateBySize: [
      '/zyz_logs/web-server/link-log.log',
    ],
    maxFileSize: 1024,
  };


  // the return config will combines to EggAppConfig
  return {
    ...defaultConfig(appInfo),
    ...config
  };
};
