export const appConfig = () => ({
  port: parseInt(process.env.APP_PORT || '3000', 10),
  env: process.env.APP_ENV || 'development',
});

export const databaseConfig = () => ({
  url: process.env.DATABASE_URL,
});

export const jwtConfig = () => ({
  secret: process.env.JWT_SECRET || 'default-secret',
  accessExpiresIn: process.env.JWT_ACCESS_EXPIRES_IN || '2h',
  refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES_IN || '30d',
});

export const redisConfig = () => ({
  host: process.env.REDIS_HOST || 'localhost',
  port: parseInt(process.env.REDIS_PORT || '6379', 10),
  password: process.env.REDIS_PASSWORD || undefined,
  db: parseInt(process.env.REDIS_DB || '0', 10),
});

export const kafkaConfig = () => ({
  brokers: (process.env.KAFKA_BROKERS || 'localhost:9092').split(','),
  clientId: process.env.KAFKA_CLIENT_ID || 'identity-service',
  groupId: process.env.KAFKA_GROUP_ID || 'identity-service-group',
});

export const smsConfig = () => ({
  // 阿里云 SMS 配置
  aliyun: {
    accessKeyId: process.env.ALIYUN_ACCESS_KEY_ID || '',
    accessKeySecret: process.env.ALIYUN_ACCESS_KEY_SECRET || '',
    signName: process.env.ALIYUN_SMS_SIGN_NAME || '榴莲皇后',
    templateCode: process.env.ALIYUN_SMS_TEMPLATE_CODE || '',
    endpoint: process.env.ALIYUN_SMS_ENDPOINT || 'dysmsapi.aliyuncs.com',
  },
  // 是否启用真实发送（开发环境可关闭）
  enabled: process.env.SMS_ENABLED === 'true',
});

export const walletConfig = () => ({
  encryptionSalt: process.env.WALLET_ENCRYPTION_SALT || 'rwa-wallet-salt',
});
