// @todo: can merge this with the hook itself
import type {
	RequestStatus,
	StatusEndPoint,
} from "../hooks/apis/useRequestStatus";

export interface FormattedRequestStatusData extends RequestStatus {
	swapTime: number;
	primaryInput: StatusEndPoint;
	primaryOutput: StatusEndPoint;
}

export const getRequestStatusData = (
	requestStatus: RequestStatus,
): FormattedRequestStatusData => {
	if (!requestStatus) return {} as FormattedRequestStatusData;

	const { destTimestamp, srcTimestamp, input, output } = requestStatus;

	// calculating the swap time (in seconds)
	const timeDiffInSeconds = destTimestamp ? destTimestamp - srcTimestamp : 0;

	return {
		...requestStatus,
		swapTime: timeDiffInSeconds,
		primaryInput: input[0],
		primaryOutput: output[0],
	} as FormattedRequestStatusData;
};
