/**
 * 编码生成工具
 */

/**
 * 生成套餐系列编码
 * 规则: PS + 年月日时分秒 + 4位随机数
 * 示例: PS20260203143025ABCD
 */
export function generateSeriesCode(): string {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')

  // 生成4位随机大写字母
  const randomChars = Array.from({ length: 4 }, () =>
    String.fromCharCode(65 + Math.floor(Math.random() * 26))
  ).join('')

  return `PS${year}${month}${day}${hours}${minutes}${seconds}${randomChars}`
}

/**
 * 生成套餐编码
 * 规则: PKG + 年月日时分秒 + 4位随机数
 * 示例: PKG20260203143025ABCD
 */
export function generatePackageCode(): string {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')

  // 生成4位随机大写字母
  const randomChars = Array.from({ length: 4 }, () =>
    String.fromCharCode(65 + Math.floor(Math.random() * 26))
  ).join('')

  return `PKG${year}${month}${day}${hours}${minutes}${seconds}${randomChars}`
}

/**
 * 生成店铺编码
 * 规则: SHOP + 年月日时分秒 + 4位随机数
 * 示例: SHOP20260314143025ABCD
 */
export function generateShopCode(): string {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')

  // 生成4位随机大写字母
  const randomChars = Array.from({ length: 4 }, () =>
    String.fromCharCode(65 + Math.floor(Math.random() * 26))
  ).join('')

  return `SHOP${year}${month}${day}${hours}${minutes}${seconds}${randomChars}`
}

/**
 * 生成运营商编码
 * 规则: CARRIER + 年月日时分秒 + 4位随机数
 * 示例: CARRIER20260328143025ABCD
 */
export function generateCarrierCode(): string {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')

  // 生成4位随机大写字母
  const randomChars = Array.from({ length: 4 }, () =>
    String.fromCharCode(65 + Math.floor(Math.random() * 26))
  ).join('')

  return `CARRIER${year}${month}${day}${hours}${minutes}${seconds}${randomChars}`
}

/**
 * 生成企业编码
 * 规则: ENT + 年月日时分秒 + 4位随机数
 * 示例: ENT20260331143025ABCD
 */
export function generateEnterpriseCode(): string {
  const now = new Date()
  const year = now.getFullYear()
  const month = String(now.getMonth() + 1).padStart(2, '0')
  const day = String(now.getDate()).padStart(2, '0')
  const hours = String(now.getHours()).padStart(2, '0')
  const minutes = String(now.getMinutes()).padStart(2, '0')
  const seconds = String(now.getSeconds()).padStart(2, '0')

  // 生成4位随机大写字母
  const randomChars = Array.from({ length: 4 }, () =>
    String.fromCharCode(65 + Math.floor(Math.random() * 26))
  ).join('')

  return `ENT${year}${month}${day}${hours}${minutes}${seconds}${randomChars}`
}
