import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http' import type { AdjustPublishedInboundFeeRequest, InboundFeeSnapshot } from './types' function feeBasePath(inboundId: string) { return `/platform/v1/inbounds/${encodeURIComponent(inboundId)}/fees` } export async function getLatestInboundFee(tenantId: string, inboundId: string) { const response = await http.get>( `${feeBasePath(inboundId)}/latest`, { params: { tenantId } }, ) return unwrapApiResponse(response) } export async function adjustPublishedInboundFee( tenantId: string, inboundId: string, payload: AdjustPublishedInboundFeeRequest, idempotencyKey: string, ) { const response = await http.put>( `${feeBasePath(inboundId)}/published`, payload, { params: { tenantId }, headers: { 'Idempotency-Key': idempotencyKey } }, ) return unwrapApiResponse(response) } export function createFeeAdjustmentIdempotencyKey() { const uuid = globalThis.crypto?.randomUUID?.() if (uuid) return `fee-adjust-${uuid}` return `fee-adjust-${Date.now()}-${Math.random().toString(36).slice(2, 12)}` }