import type { PageParam } from '@/api'
import type { AppRole } from '../appUser/model'

export interface AppProduct {
  productId?: number
  productName?: string
  productCode?: string
  productSecret?: string
  appType?: number
  categoryId?: number
  industryParent?: string
  industryChild?: string
  logo?: string
  icon?: string
  qrcode?: string
  screenshots?: string
  description?: string
  content?: string
  keywords?: string
  domain?: string
  prefix?: string
  packageName?: string
  homeUrl?: string
  adminUrl?: string
  apiUrl?: string
  downloadUrl?: string
  version?: string
  edition?: string
  minVersion?: string
  priceType?: string
  price?: number
  linePrice?: number
  renewPrice?: number
  deliveryMethod?: number
  chargingMethod?: number
  subscriptionPeriod?: string
  publishStatus?: string
  publishTime?: string
  reviewTime?: string
  reviewerId?: number
  rejectReason?: string
  clicks?: number
  installs?: number
  downloads?: number
  rating?: number
  likes?: number
  developer?: string
  developerPhone?: string
  developerEmail?: string
  recommend?: number
  official?: number
  market?: number
  showIndex?: number
  searchEnabled?: number
  templateId?: number
  style?: string
  config?: string
  themeColor?: string
  lang?: string
  icpNo?: string
  policeNo?: string
  status?: number
  statusText?: string
  running?: number
  expirationTime?: string
  sortNumber?: number
  deleted?: number
  userId?: number
  tenantId?: number
  createTime?: string
  updateTime?: string
  /** 当前用户在该应用中的角色（仅 joined/accessible 查询返回） */
  myRole?: AppRole
}

export interface AppProductParam extends PageParam {
  appType?: number
  categoryId?: number
  publishStatus?: string
  status?: number
  keywords?: string
  developer?: string
  market?: number
  official?: number
  recommend?: number
  userId?: number
  tenantId?: number
}

// App Type 枚举
export const APP_TYPE = {
  WEBSITE: 10,
  WECHAT_MP: 20,
  DOUYIN_MP: 30,
  BAIDU_MP: 40,
  ALIPAY_MP: 50,
  ANDROID: 60,
  IOS: 70,
  MACOS: 80,
  WINDOWS: 90,
  PLUGIN: 100,
} as const

export type APP_TYPE_KEY = keyof typeof APP_TYPE

export const APP_TYPE_NAME: Record<number, string> = {
  [APP_TYPE.WEBSITE]: '网站',
  [APP_TYPE.WECHAT_MP]: '微信小程序',
  [APP_TYPE.DOUYIN_MP]: '抖音小程序',
  [APP_TYPE.BAIDU_MP]: '百度小程序',
  [APP_TYPE.ALIPAY_MP]: '支付宝小程序',
  [APP_TYPE.ANDROID]: 'Android APP',
  [APP_TYPE.IOS]: 'iOS APP',
  [APP_TYPE.MACOS]: 'macOS 应用',
  [APP_TYPE.WINDOWS]: 'Windows 应用',
  [APP_TYPE.PLUGIN]: '插件',
}

// Publish Status 枚举
export const PUBLISH_STATUS = {
  DEVELOPING: 'developing',
  PENDING_REVIEW: 'pending_review',
  PUBLISHED: 'published',
  REJECTED: 'rejected',
  DEPRECATED: 'deprecated',
} as const

export type PUBLISH_STATUS_KEY = keyof typeof PUBLISH_STATUS

export const PUBLISH_STATUS_NAME: Record<string, string> = {
  [PUBLISH_STATUS.DEVELOPING]: '开发中',
  [PUBLISH_STATUS.PENDING_REVIEW]: '待审核',
  [PUBLISH_STATUS.PUBLISHED]: '已上架',
  [PUBLISH_STATUS.REJECTED]: '审核未通过',
  [PUBLISH_STATUS.DEPRECATED]: '已下架',
}

// Price Type 枚举
export const PRICE_TYPE = {
  FREE: 'free',
  ONE_TIME: 'one_time',
  SUBSCRIPTION: 'subscription',
} as const

export type PRICE_TYPE_KEY = keyof typeof PRICE_TYPE

export const PRICE_TYPE_NAME: Record<string, string> = {
  [PRICE_TYPE.FREE]: '免费',
  [PRICE_TYPE.ONE_TIME]: '一次性',
  [PRICE_TYPE.SUBSCRIPTION]: '订阅',
}

// Edition 枚举
export const EDITION = {
  STANDARD: 'standard',
  PROFESSIONAL: 'professional',
  PERPETUAL: 'perpetual',
} as const

export type EDITION_KEY = keyof typeof EDITION

export const EDITION_NAME: Record<string, string> = {
  [EDITION.STANDARD]: '标准版',
  [EDITION.PROFESSIONAL]: '专业版',
  [EDITION.PERPETUAL]: '永久授权',
}

// Status 枚举
export const STATUS = {
  INACTIVE: 0,
  RUNNING: 1,
  MAINTENANCE: 2,
  CLOSED: 3,
  ARREARS: 4,
  VIOLATION: 5,
} as const

export type STATUS_KEY = keyof typeof STATUS

export const STATUS_NAME: Record<number, string> = {
  [STATUS.INACTIVE]: '未开通',
  [STATUS.RUNNING]: '运行中',
  [STATUS.MAINTENANCE]: '维护中',
  [STATUS.CLOSED]: '已关闭',
  [STATUS.ARREARS]: '已欠费',
  [STATUS.VIOLATION]: '违规停机',
}
