/**
   * Prepares the channel and playlist entities for the subscription to the
   * specified channel.
   *
   * @param entityManager The current entity manager in a transaction used to
   *        update the subscriptions.
   * @param channel The entity representing the channel for which the
   *        subscription is being prepared.
   * @return The channel entity representing the provided channel within this
   *         extension's database.
   */
  async [PRIVATE.prepareSubscription](entityManager: EntityManager,
      channel: Channel): {knownChannel: Channel, playlist: Playlist} {
    let knownChannel = await entityManager.find(Channel, channel.id)
    if (!knownChannel) {
      knownChannel = await entityManager.persist(channel)
    }
    let playlist = await entityManager.find(
        Playlist,
        knownChannel.uploadsPlaylistId
    )
    if (!playlist) {
      playlist = await this[PRIVATE.fetchUploadsPlaylist](channel)
      playlist = await entityManager.persist(playlist)
    }

    return {
      knownChannel,
      playlist
    }
  }
  /**
   * Processes the provided subscription, adding it to the subscriptions in the
   * database if not already present, and checking, updating and saving the
   * related channel and uploads playlist.
   *
   * @param entityManager The current entity manager in a transaction used to
   *        update the subscriptions.
   * @param knownSubscriptions A map of channel IDs to subscriptions to the
   *        channels.
   * @param subscription The subscription to the channel.
   * @param channel The channel to which the user is subscribed.
   */
  async [PRIVATE.processSubscription](entityManager: EntityManager,
      knownSubscriptions: Map<string, Subscription>,
      subscription: Subscription, channel: Channel): void {
    // save new subscriptions
    if (!knownSubscriptions.has(channel.id)) {
      await entityManager.persist(subscription)
    }

    let {knownChannel, playlist} = await this[PRIVATE.prepareSubscription](
      entityManager,
      channel
    )

    // update existing subscriptions
    this[PRIVATE.updateKnownSubscription](
      entityManager,
      account,
      knownChannel,
      playlist
    )
  }