/**
 * 套餐管理相关常量配置
 */

// ==================== 套餐类型 ====================

/**
 * 套餐类型枚举
 */
export enum PackageType {
  FORMAL = 'formal', // 正式套餐
  ADDON = 'addon' // 加油包
}

/**
 * 套餐类型选项
 */
export const PACKAGE_TYPE_OPTIONS = [
  {
    label: '正式套餐',
    value: PackageType.FORMAL,
    type: 'primary' as const
  },
  {
    label: '加油包',
    value: PackageType.ADDON,
    type: 'success' as const
  }
]

/**
 * 套餐类型映射
 */
export const PACKAGE_TYPE_MAP = PACKAGE_TYPE_OPTIONS.reduce(
  (map, item) => {
    map[item.value] = item
    return map
  },
  {} as Record<PackageType, { label: string; value: PackageType; type: 'primary' | 'success' }>
)

/**
 * 获取套餐类型标签
 */
export function getPackageTypeLabel(type: string): string {
  return PACKAGE_TYPE_MAP[type as PackageType]?.label || '未知'
}

/**
 * 获取套餐类型标签类型
 */
export function getPackageTypeTag(type: string) {
  return PACKAGE_TYPE_MAP[type as PackageType]?.type || 'info'
}

// ==================== 流量类型 ====================

/**
 * 流量类型枚举
 */
export enum DataType {
  REAL = 'real', // 真实流量
  VIRTUAL = 'virtual' // 虚拟流量
}

/**
 * 流量类型选项
 */
export const DATA_TYPE_OPTIONS = [
  {
    label: '真实流量',
    value: DataType.REAL,
    type: 'success' as const
  },
  {
    label: '虚拟流量',
    value: DataType.VIRTUAL,
    type: 'warning' as const
  }
]

/**
 * 流量类型映射
 */
export const DATA_TYPE_MAP = DATA_TYPE_OPTIONS.reduce(
  (map, item) => {
    map[item.value] = item
    return map
  },
  {} as Record<DataType, { label: string; value: DataType; type: 'success' | 'warning' }>
)

/**
 * 获取流量类型标签
 */
export function getDataTypeLabel(type: string): string {
  return DATA_TYPE_MAP[type as DataType]?.label || '未知'
}

/**
 * 获取流量类型标签类型
 */
export function getDataTypeTag(type: string) {
  return DATA_TYPE_MAP[type as DataType]?.type || 'info'
}

// ==================== 上架状态 ====================

/**
 * 上架状态枚举
 */
export enum ShelfStatus {
  ON_SHELF = 1, // 上架
  OFF_SHELF = 2 // 下架
}

/**
 * 上架状态选项
 */
export const SHELF_STATUS_OPTIONS = [
  {
    label: '上架',
    value: ShelfStatus.ON_SHELF,
    type: 'success' as const,
    text: '上架'
  },
  {
    label: '下架',
    value: ShelfStatus.OFF_SHELF,
    type: 'info' as const,
    text: '下架'
  }
]

/**
 * 上架状态选项（精简版，用于搜索表单和下拉选择）
 */
export const SHELF_STATUS_SELECT_OPTIONS = [
  { label: '上架', value: ShelfStatus.ON_SHELF },
  { label: '下架', value: ShelfStatus.OFF_SHELF }
]

/**
 * 上架状态映射
 */
export const SHELF_STATUS_MAP = SHELF_STATUS_OPTIONS.reduce(
  (map, item) => {
    map[item.value] = item
    return map
  },
  {} as Record<
    ShelfStatus,
    { label: string; value: ShelfStatus; type: 'success' | 'info'; text: string }
  >
)

/**
 * 获取上架状态标签
 */
export function getShelfStatusLabel(status: number): string {
  return SHELF_STATUS_MAP[status as ShelfStatus]?.label || '未知'
}

/**
 * 获取上架状态文本
 */
export function getShelfStatusText(status: number): string {
  return SHELF_STATUS_MAP[status as ShelfStatus]?.text || '未知'
}

/**
 * 获取上架状态标签类型
 */
export function getShelfStatusType(status: number) {
  return SHELF_STATUS_MAP[status as ShelfStatus]?.type || 'info'
}

// ==================== 定价模式 ====================

/**
 * 定价模式枚举
 */
export enum PricingMode {
  FIXED = 'fixed', // 固定金额
  PERCENT = 'percent' // 百分比
}

/**
 * 定价模式选项
 */
export const PRICING_MODE_OPTIONS = [
  {
    label: '固定金额',
    value: PricingMode.FIXED,
    type: 'primary' as const
  },
  {
    label: '百分比',
    value: PricingMode.PERCENT,
    type: 'success' as const
  }
]

/**
 * 定价模式映射
 */
export const PRICING_MODE_MAP = PRICING_MODE_OPTIONS.reduce(
  (map, item) => {
    map[item.value] = item
    return map
  },
  {} as Record<PricingMode, { label: string; value: PricingMode; type: 'primary' | 'success' }>
)

/**
 * 获取定价模式标签
 */
export function getPricingModeLabel(mode: string): string {
  return PRICING_MODE_MAP[mode as PricingMode]?.label || '未知'
}

/**
 * 获取定价模式标签类型
 */
export function getPricingModeTag(mode: string) {
  return PRICING_MODE_MAP[mode as PricingMode]?.type || 'info'
}

// ==================== 价格来源 ====================

/**
 * 价格来源枚举
 */
export enum PriceSource {
  SERIES_PRICING = 'series_pricing', // 系列加价
  PACKAGE_OVERRIDE = 'package_override' // 单套餐覆盖
}

/**
 * 价格来源选项
 */
export const PRICE_SOURCE_OPTIONS = [
  {
    label: '系列加价',
    value: PriceSource.SERIES_PRICING,
    type: 'primary' as const
  },
  {
    label: '单套餐覆盖',
    value: PriceSource.PACKAGE_OVERRIDE,
    type: 'warning' as const
  }
]

/**
 * 价格来源映射
 */
export const PRICE_SOURCE_MAP = PRICE_SOURCE_OPTIONS.reduce(
  (map, item) => {
    map[item.value] = item
    return map
  },
  {} as Record<PriceSource, { label: string; value: PriceSource; type: 'primary' | 'warning' }>
)

/**
 * 获取价格来源标签
 */
export function getPriceSourceLabel(source: string): string {
  return PRICE_SOURCE_MAP[source as PriceSource]?.label || '未知'
}

/**
 * 获取价格来源标签类型
 */
export function getPriceSourceTag(source: string) {
  return PRICE_SOURCE_MAP[source as PriceSource]?.type || 'info'
}

// ==================== 状态值映射工具 ====================

/**
 * 前端状态值 (CommonStatus: 0/1) 转换为后端 API 状态值 (1/2)
 * @param frontendStatus 前端状态值 (0:禁用, 1:启用)
 * @returns 后端状态值 (1:启用, 2:禁用)
 */
export function frontendStatusToApi(frontendStatus: number): number {
  return frontendStatus === 1 ? 1 : 2
}

/**
 * 后端 API 状态值 (1/2) 转换为前端状态值 (CommonStatus: 0/1)
 * @param apiStatus 后端状态值 (1:启用, 2:禁用)
 * @returns 前端状态值 (0:禁用, 1:启用)
 */
export function apiStatusToFrontend(apiStatus: number): number {
  return apiStatus === 1 ? 1 : 0
}
