import { env } from '@blocklet/sdk/lib/env';

export const paymentStatCronTime: string = '0 1 0 * * *'; // 默认每天一次，计算前一天的
export const subscriptionCronTime: string = process.env.SUBSCRIPTION_CRON_TIME || '0 */30 * * * *'; // 默认每 30 min 行一次
export const notificationCronTime: string = process.env.NOTIFICATION_CRON_TIME || '0 5 */6 * * *'; // 默认每6个小时执行一次
export const expiredSessionCleanupCronTime: string = process.env.EXPIRED_SESSION_CLEANUP_CRON_TIME || '0 1 * * * *'; // 默认每小时执行一次
export const notificationCronConcurrency: number = Number(process.env.NOTIFICATION_CRON_CONCURRENCY) || 8; // 默认并发数为 8
export const stripeInvoiceCronTime: string = process.env.STRIPE_INVOICE_CRON_TIME || '0 */30 * * * *'; // 默认每 30min 执行一次
export const stripePaymentCronTime: string = process.env.STRIPE_PAYMENT_CRON_TIME || '0 */20 * * * *'; // 默认每 20min 执行一次
export const stripeSubscriptionCronTime: string = process.env.STRIPE_SUBSCRIPTION_CRON_TIME || '0 10 */8 * * *'; // 默认每 8小时 执行一次
export const revokeStakeCronTime: string = process.env.REVOKE_STAKE_CRON_TIME || '0 */5 * * * *'; // 默认每 5 min 执行一次
export const daysUntilCancel: string | undefined = process.env.DAYS_UNTIL_CANCEL;
export const meteringSubscriptionDetectionCronTime: string =
  process.env.METERING_SUBSCRIPTION_DETECTION_CRON_TIME || '0 0 10 * * *'; // 默认每天 10:00 执行
export const overdueDetectionCronTime: string = process.env.OVERDUE_DETECTION_CRON_TIME || '0 0 10 * * *'; // 默认每天 10:00 执行
export const overdueThreshold: number = process.env.OVERDUE_THRESHOLD ? +process.env.OVERDUE_THRESHOLD : 5; // 默认超额阈值为 5
export const depositVaultCronTime: string = process.env.DEPOSIT_VAULT_CRON_TIME || '0 */5 * * * *'; // 默认每 5 min 执行一次
export const creditConsumptionCronTime: string = process.env.CREDIT_CONSUMPTION_CRON_TIME || '0 */10 * * * *'; // 默认每 10 min 执行一次
export const vendorStatusCheckCronTime: string = process.env.VENDOR_STATUS_CHECK_CRON_TIME || '0 */10 * * * *'; // 默认每 10 min 执行一次
export const vendorReturnScanCronTime: string = process.env.VENDOR_RETURN_SCAN_CRON_TIME || '0 */10 * * * *'; // 默认每 10 min 执行一次
export const quoteCleanupCronTime: string = process.env.QUOTE_CLEANUP_CRON_TIME || '0 0 2 * * *'; // 默认每天凌晨 2 点执行一次
export const vendorTimeoutMinutes: number = process.env.VENDOR_TIMEOUT_MINUTES
  ? +process.env.VENDOR_TIMEOUT_MINUTES
  : 10; // 默认 10 分钟超时
export const webhookAlertWindowMinutes: number = process.env.WEBHOOK_ALERT_WINDOW_MINUTES
  ? +process.env.WEBHOOK_ALERT_WINDOW_MINUTES
  : 10; // webhook 连续失败告警时间窗口，默认 10 分钟
export const webhookAlertMinFailures: number = process.env.WEBHOOK_ALERT_MIN_FAILURES
  ? +process.env.WEBHOOK_ALERT_MIN_FAILURES
  : 3; // webhook 触发告警的最小失败次数，默认 3 次

export const shortUrlApiKey: string = process.env.SHORT_URL_API_KEY || '';
export const shortUrlDomain: string = process.env.SHORT_URL_DOMAIN || 's.abtnet.io';

// sequelize 配置相关
export const sequelizeOptionsPoolMin: number = process.env.SEQUELIZE_OPTIONS_POOL_MIN
  ? +process.env.SEQUELIZE_OPTIONS_POOL_MIN
  : 0;
export const sequelizeOptionsPoolMax: number = process.env.SEQUELIZE_OPTIONS_POOL_MAX
  ? +process.env.SEQUELIZE_OPTIONS_POOL_MAX
  : 5;
export const sequelizeOptionsPoolIdle: number = process.env.SEQUELIZE_OPTIONS_POOL_IDLE
  ? +process.env.SEQUELIZE_OPTIONS_POOL_IDLE
  : 10 * 1000;

export const updateDataConcurrency: number = process.env.UPDATE_DATA_CONCURRENCY
  ? +process.env.UPDATE_DATA_CONCURRENCY
  : 5; // 默认并发数为 5

// When set to 'true' or '1', the system stops accepting new orders.
// Existing checkout sessions can still be viewed but new submissions will be rejected.
export const stopAcceptingOrders: boolean =
  process.env.PAYMENT_KIT_STOP_ACCEPTING_ORDERS === 'true' || process.env.PAYMENT_KIT_STOP_ACCEPTING_ORDERS === '1';

export const exchangeRateCacheTTLSeconds: number = process.env.EXCHANGE_RATE_CACHE_TTL_SECONDS
  ? +process.env.EXCHANGE_RATE_CACHE_TTL_SECONDS
  : 10 * 60;

// System-level maximum pending amount limit (in token format, e.g., "10")
// Default is 0 (disabled). Set PAYMENT_KIT_MAX_PENDING_AMOUNT to enable this limit.
export const systemMaxPendingAmount: number = process.env.PAYMENT_KIT_MAX_PENDING_AMOUNT
  ? +process.env.PAYMENT_KIT_MAX_PENDING_AMOUNT
  : 5;

export default {
  ...env,
};
