import { rpcOrNull, rpcOrValue } from '@/services/analytics/rpc.uts'

/**
 * 系统配置项模型
 */
export type SystemConfig = {
  config_key : string
  config_value : UTSJSONObject
  description ?: string
  updated_at ?: string
}

/**
 * 获取指定键的系统配置
 */
export async function getSystemConfig(key : string) : Promise<UTSJSONObject | null> {
  const res = await rpcOrNull('rpc_admin_system_config_get', {
    p_key: key
  } as UTSJSONObject)
  
  if (res == null) return null
  return res as UTSJSONObject
}

/**
 * 保存/更新系统配置
 */
export async function saveSystemConfig(key : string, value : UTSJSONObject, description : string | null = null) : Promise<boolean> {
  const ok = await rpcOrValue('rpc_admin_system_config_save', {
    p_key: key,
    p_value: value,
    p_description: description
  } as any)
  
  return ok === true
}

/**
 * 批量获取配置 (可选扩展)
 * 逻辑：如果后续有需求，可以补齐 rpc_admin_system_config_batch_get
 */
