/**
 * 资产信息页面类型定义
 */

import type { AssetExchangeTrace, AssetPollingStatus, ExpiryEstimateStatus } from '@/types/api'

// 资产类型枚举
export type AssetType = 'card' | 'device'

// 资产基本信息接口
export interface AssetInfo {
  id: number
  asset_id: number
  asset_type: AssetType
  identifier: string
  iccid?: string
  imei?: string
  msisdn?: string
  carrier_type?: string
  carrier_name?: string
  real_name_status?: number
  activation_status_name?: string
  realname_policy?: string
  network_status?: string
  current_month_used_data?: number
  device_type?: string
  device_name?: string
  device_status?: number
  online_status?: number
  virtual_no?: string
  sn?: string
  cards?: BindingCard[]
  status?: number
  gateway_card_imei?: string
  gateway_extend?: string
  total_virtual_used_mb?: number | null
  total_virtual_remaining_mb?: number | null
  estimated_final_expires_at?: string | null
  days_until_final_expiry?: number | null
  expiry_estimate_status?: ExpiryEstimateStatus
  expiry_estimate_status_name?: string | null
  is_expiring?: boolean
  last_sync_time?: string | null
  last_data_check_at?: string | null
  last_real_name_check_at?: string | null
  last_card_status_check_at?: string | null
  polling?: AssetPollingStatus | null
  exchange_trace?: AssetExchangeTrace | null
}

// 设备绑定卡信息
export interface BindingCard {
  id: number
  card_id?: number
  iccid: string
  msisdn?: string
  is_current: boolean
  status?: number
  carrier_name?: string
  slot_position?: number
  network_status?: number
  real_name_status?: number
  real_name_at?: string | null
  realname_policy?: string
  gateway_extend?: string
  last_data_check_at?: string | null
  last_real_name_check_at?: string | null
  last_card_status_check_at?: string | null
}

// 设备实时信息接口
export interface DeviceRealtimeInfo {
  device_id?: number | string
  status?: string
  online_status?: number
  report_time?: string
  boot_time?: string
  running_time?: string
  run_time?: string
  connect_time?: string
  last_online_time?: string
  battery_level?: number | null
  client_number?: number
  max_clients?: number
  rssi?: string
  rsrp?: string
  rsrq?: string
  sinr?: string
  signal_quality?: string
  signal_bad_reason?: string
  band?: string
  pci?: string
  wifi_enabled?: boolean | number
  ssid?: string
  wifi_ssid?: string
  wifi_password?: string
  network_type?: string
  ip_address?: string
  wan_ip?: string
  lan_ip?: string
  mac_address?: string
  apn?: string
  current_iccid?: string
  imsi?: string
  uplink_rate?: number
  downlink_rate?: number
  uplink_speed_limit?: number
  downlink_speed_limit?: number
  limit_speed?: number
  switch_mode?: string
  imei?: string
  model?: string
  software_version?: string
  firmware_version?: string
  sync_interval?: number
  last_sync_time?: string
  last_update_time?: string
}

// 套餐信息接口
export interface PackageInfo {
  id: number
  package_usage_id?: number
  package_id: number
  order_id?: number
  package_name: string
  package_price: number
  paid_amount?: number
  real_total_mb: number
  real_used_mb: number
  real_remaining_mb: number
  virtual_total_mb: number
  virtual_used_mb: number
  virtual_remaining_mb: number
  start_time: string
  expire_time: string
  status: number
  status_name?: string
  duration_days?: number
  data_usage_mb?: number
  reduction_pct?: number // 展示增幅比例
  package_type?: string // 套餐类型: formal（正式套餐）/ addon（加油包）
  enable_virtual_data?: boolean // 是否启用虚流量
  order_no?: string // 订单号
  created_at?: string // 创建时间
}

// 钱包信息接口 (使用已有的 AssetWalletResponse)
export interface WalletInfo {
  total_balance: number
  available_balance: number
  frozen_balance: number
  status: number
}

// 限速表单接口
export interface SpeedLimitForm {
  download_speed: number
  upload_speed: number
}

// 切卡表单接口
export interface SwitchCardForm {
  target_iccid: string
}

// WiFi配置表单接口
export interface WiFiForm {
  card_no: string // 流量卡号（ICCID）
  enabled: boolean
  ssid: string
  password: string
}

// 充值表单接口
export interface RechargeForm {
  package_id?: number
  payment_method: 'wallet' | 'offline'
  payment_voucher?: string
}

// 流量详单日记录
export interface DailyRecord {
  date: string
  data_used: number
}

// 流量详单数据
export interface DailyRecordsData {
  package_info: PackageInfo
  records: DailyRecord[]
}

// 订单历史数据
export interface OrderHistoryData {
  current_order?: any
  previous_orders: any[]
  total: number
  replacement_chain?: string[]
}
