export type AdminDefaultUser = {
  username: string
  password: string
  role: string
  status?: string
}

export type KuaishouFeifeiProductRule = {
  id?: string
  productName: string
  normalizedProductName?: string
  productCode: string
  skuName?: string
  enabled?: boolean
  notes?: string
}

export type AffiliateDashSkuMapping = Record<string, string>

export type RuntimeConfig = {
  server: {
    port: number
    /** Express trust proxy：true/false、反代层数或 loopback 等预定义子网；默认 1（单层反代）。 */
    trustProxy?: boolean | number | string
  }
  data: {
    root: string
  }
  logging: {
    level: string
    /** integration 通道（外部对接日志文件）最低级别，默认 warn */
    integrationLevel: string
    retentionDays: number
    /** 单个日志文件大小上限（MB），超出后轮转。 */
    maxFileSizeMb?: number
    /** 同一日期最多保留的日志文件数量（含当前文件）。 */
    maxFiles?: number
  }
  retention: {
    rawPayloadDays: number
    taskEventDays: number
    webhookEventDays: number
    auditLogDays: number
  }
  database: {
    url: string
    ssl: boolean
    maxConnections: number
    idleTimeoutMs?: number
    connectionTimeoutMs?: number
    statementTimeoutMs?: number
    /** 超过该时长的 SQL 记录慢查询告警；0 表示关闭。 */
    slowQueryThresholdMs?: number
  }
  storage: {
    mode: 'minio' | 'dual' | 'oss'
    endpoint: string
    bucket: string
    accessKeyId: string
    secretAccessKey: string
    region: string
    maxUploadSizeMb: number
    oss: {
      endpoint: string
      bucket: string
      accessKeyId: string
      secretAccessKey: string
      region: string
    }
  }
  orders: {
    claimBaseUrl: string
    tokenTtlHours: number
  }
  admin: {
    sessionSecret: string
    sessionTtlHours: number
    defaultUsers: AdminDefaultUser[]
  }
  platforms: {
    ninetyone: {
      userId: string
      secret: string
      version: string
      shopId: string
      shopName: string
      timestampToleranceSeconds: number
      cardsEncoding: string
    }
    cloudtentacles: {
      baseUrl: string
      timeoutMs: number
      sendSmsPath: string
      loginPath: string
      userInfoPath: string
      assetPath: string
      permissionPath: string
      categoriesPath: string
      skuListPath: string
      skuBuyPath: string
      skuUsePath: string
      knapsackPath: string
      vnListPath: string
      vnAppointPath: string
      vnGenerateLoginCodePath: string
      vnVerifCodePath: string
      vnVerifyLoginCodePath: string
      vnBindUrlPath: string
      vnBindInfoPath: string
      vnBackPath: string
      bindUrlTtlSeconds: number
      bindUrlProbeIntervalSeconds: number
      bindUrlProbeTimeoutMs: number
      bindUrlProbeUserAgent: string
      bindUrlProbeEndpoint: string
      bindUrlProbeChartId: string
      bindUrlProbeSubChartId: string
      bindUrlProbeIdeToken: string
      bindUrlProbeActivityUrl: string
      bindUrlProbeReferer: string
      bindUrlProbeExtraCookie: string
      publicKeyPem: string
      clientSource: string
      deviceId: string
      deviceType: number
    }
    kuaishouIndustry: {
      appKey: string
      appSecret: string
      signSecret: string
      messageSecret: string
      provider: string
      platform: string
      shopId: string
      shopName: string
      version: string
    }
    kuaishouFeifei: {
      enabled: boolean
      baseUrl: string
      appKey: string
      appSecret: string
      timeoutMs: number
      notifyUrl: string
      productRules: KuaishouFeifeiProductRule[]
    }
    affiliateDash: {
      enabled: boolean
      baseUrl: string
      appKey: string
      appSecret: string
      callbackSecret: string
      timeoutMs: number
      notifyUrl: string
      timestampToleranceSeconds: number
      preferredMatchEnabled: boolean
      skuMapping: AffiliateDashSkuMapping
    }
  }
  worker: {
    sms: {
      provider: string
      accessKeyId: string
      accessKeySecret: string
      signName: string
      templateCode: string
      codeTtlSeconds: number
      cooldownSeconds: number
      dailyLimit: number
    }
    /** 打手端订单详情是否展示流转记录（默认关闭，仅后台可见） */
    orderTimelineVisible: boolean
  }
  cors: {
    allowedOrigins: string[]
  }
}
