import type { Service } from "./types";

export function getServiceLaunchLink(service: Pick<Service, "url" | "launchUrl">): string {
  return service.launchUrl?.trim() || service.url.trim();
}

export function createServiceLaunchLinkPatch(value: string): Pick<Service, "url" | "launchUrl"> {
  const launchLink = value.trim();

  return {
    url: launchLink,
    launchUrl: launchLink || null,
  };
}

export function syncServiceLaunchLink(service: Service): Service {
  return {
    ...service,
    ...createServiceLaunchLinkPatch(getServiceLaunchLink(service)),
  };
}
