import { CID } from 'multiformats/cid';
import { configure } from '../../lib/configure.js';
import { toUrlSearchParams } from '../../lib/to-url-search-params.js';
export const createRmLink = configure(api => {
  async function rmLink(cid, dLink, options = {}) {
    const res = await api.post('object/patch/rm-link', {
      signal: options.signal,
      searchParams: toUrlSearchParams({
        arg: [
          `${ cid }`,
          dLink.Name || dLink.name || null
        ],
        ...options
      }),
      headers: options.headers
    });
    const {Hash} = await res.json();
    return CID.parse(Hash);
  }
  return rmLink;
});