import { formatDateTime } from './format'
import type { ExpiryEstimateStatus } from '@/types/api'

export interface ExpiryEstimate {
  estimated_final_expires_at?: string | null
  days_until_final_expiry?: number | null
  expiry_estimate_status?: ExpiryEstimateStatus | null
  expiry_estimate_status_name?: string | null
  is_expiring?: boolean
}

export const getExpiryEstimateText = (estimate: ExpiryEstimate): string => {
  switch (estimate.expiry_estimate_status) {
    case 'exact':
      return estimate.estimated_final_expires_at
        ? formatDateTime(estimate.estimated_final_expires_at)
        : '-'
    case 'waiting_activation':
      return '待激活后起算'
    case 'invalid_data':
      return '数据异常'
    case 'none':
    default:
      return '-'
  }
}

export const getExpiryEstimateTooltip = (estimate: ExpiryEstimate): string => {
  if (!estimate.is_expiring || estimate.days_until_final_expiry == null) return ''
  return `剩余${estimate.days_until_final_expiry}天`
}
