import appSettings from '@/core/config/app-settings'
import { digestHex } from '@/core/infra/hash-digest'
import { sortObjectKeys, buildQueryString } from './query-serialize'

export function buildApiSignature(relativePath, payload = {}) {
	const merged = {
		...(typeof payload === 'object' && payload !== null ? payload : {}),
		appKey: digestHex(appSettings.socketurl)
	}
	const ordered = sortObjectKeys(merged)
	const query = buildQueryString(ordered)
	return digestHex(`/api${relativePath}?${query}`)
}
