//#region src/testing.ts
const DEFAULT_LABEL = {
	id: "label-memory-1",
	trackingNumber: "TRACK-MEMORY-001"
};
const DEFAULT_TRACK = {
	trackingNumber: "TRACK-MEMORY-001",
	status: "in_transit"
};
function createMemoryCarrierAdapter(options = {}) {
	let buyLabelCallCount = 0;
	return {
		kind: "memory",
		capabilities: {
			webhooks: true,
			tracking: true
		},
		get buyLabelCallCount() {
			return buyLabelCallCount;
		},
		async buyLabel(args) {
			buyLabelCallCount += 1;
			if (options.buyLabel) return options.buyLabel(args);
			return {
				...DEFAULT_LABEL,
				id: `label-${args.idempotencyKey}`
			};
		},
		async track(trackingNumber) {
			if (options.track) return options.track(trackingNumber);
			return {
				...DEFAULT_TRACK,
				trackingNumber
			};
		},
		async verifyWebhook(req) {
			if (options.verifyWebhook) return options.verifyWebhook(req);
			return null;
		}
	};
}
function createMemoryStorageAdapter() {
	const puts = [];
	return {
		puts,
		async put(key, body) {
			puts.push({
				key,
				body
			});
		},
		async signedUrl(key, ttlSeconds) {
			const expiresAt = new Date(Date.now() + ttlSeconds * 1e3);
			return {
				url: `https://memory-storage.test/${encodeURIComponent(key)}?ttl=${ttlSeconds}`,
				expiresAt
			};
		}
	};
}
const DEFAULT_MEMORY_ADDRESS = {
	line1: "1 Memory Lane",
	city: "Testville",
	postalCode: "12345",
	country: "US"
};
function createMemoryFulfillmentPorts(options) {
	const notifications = [];
	const storage = options.storage ?? createMemoryStorageAdapter();
	return {
		db: options.db,
		storage,
		carriers: options.carriers,
		get notifications() {
			return notifications;
		},
		resolveBlobKey: options.resolveBlobKey ?? (async (line) => `blob:${line.variantId}`),
		resolveShippingAddress: options.resolveShippingAddress ?? (async () => DEFAULT_MEMORY_ADDRESS),
		notify: async (notification) => {
			notifications.push(notification);
			await options.notify?.(notification);
		}
	};
}
//#endregion
export { DEFAULT_MEMORY_ADDRESS, createMemoryCarrierAdapter, createMemoryFulfillmentPorts, createMemoryStorageAdapter };
