import { createDeckBucketActor, initDeckBucket } from './manager.utils';
import { toArray, toTimestamp } from './did.utils';
export const uploadDeckData = async ({ deck, managerActor, identity, host }) => {
  console.log('Deck IC about to SET');
  const t0 = performance.now();
  const bucket = await initDeckBucket({ managerActor, deckId: deck.id });
  const deckBucket = await createDeckBucketActor({ identity, bucket, host });
  await deckBucket.set({
    deckId: deck.id,
    data: await toArray(deck.data),
    created_at: toTimestamp(deck.data.created_at || new Date()),
    updated_at: toTimestamp(deck.data.updated_at || new Date())
  });
  const t1 = performance.now();
  console.log('Deck IC SET done', t1 - t0);
  const t2 = performance.now();
  // TODO: remove, just for test
  console.log('Deck IC Get:', await deckBucket.get(), performance.now() - t2);
};
export const uploadSlideData = async ({ slide, deckId, managerActor, identity, host }) => {
  console.log('Slide IC about to SET');
  const t0 = performance.now();
  const t4 = performance.now();
  const bucket = await initDeckBucket({ managerActor, deckId });
  const t5 = performance.now();
  console.log('Bucket retrieved', t5 - t4);
  const deckBucket = await createDeckBucketActor({ identity, bucket, host });
  await deckBucket.setSlide({
    slideId: slide.id,
    data: await toArray(slide.data),
    created_at: toTimestamp(slide.data.created_at || new Date()),
    updated_at: toTimestamp(slide.data.updated_at || new Date())
  });
  const t1 = performance.now();
  console.log('Slide IC SET done', t1 - t0);
  const t2 = performance.now();
  // TODO: remove, just for test
  console.log('Slide IC Get:', await deckBucket.getSlide(slide.id), performance.now() - t2);
};
export const deleteSlide = async ({ slideId, deckId, managerActor, identity, host }) => {
  if (!slideId) {
    return;
  }
  console.log('Slide IC about to DEL');
  const t0 = performance.now();
  const bucket = await initDeckBucket({ managerActor, deckId });
  const deckBucket = await createDeckBucketActor({ identity, bucket, host });
  await deckBucket.delSlide(slideId);
  const t1 = performance.now();
  console.log('Slide IC DEL done', t1 - t0);
};
