 
 import Foundation
 
+/// Receiver of crawler-related events.
 public protocol CrawlerDelegate: AnyObject {
-  func willVisit(url: URL)
-  func wordFound(at url: URL)
+
+  /// Called whenever the crawler is about to visit a new webpage.
+  func crawler(_ crawler: Crawler, willVisitUrl url: URL)
+
+  /// Called whenever the crawler finds the searched word in a webpage.
+  ///
+  /// - Note: This call is fired only (up to) one time per webpage, regardless
+  ///   of how many times the word is found in that webpage.
+  func crawler(_ crawler: Crawler, didFindWordAt url: URL)
+
+  /// Called once the crawler ends its execution.
+  func crawlerDidFinish(_ crawler: Crawler)
 }
 
 /// A web crawler.

  func parse(document: String, url: URL) {
    func find(word: String, from document: String) {
      guard document.contains(word) else { return }
      wordFoundCallback(url)
    }

    func collectLinks(from document: String) -> [URL] {

  ///   - startURL: The starting page URL (must contain http:// or https://).
  ///   - maximumPagesToVisit: The maximum number of web pages to visit.
  ///   - word: The word to look for.
  public init(
    startURL: URL,
    maximumPagesToVisit: Int,
    wordToSearch word: String
  ) {
    self.startURL = startURL
    self.pagesToVisit = [startURL]
    self.maximumPagesToVisit = maximumPagesToVisit
    self.wordToSearch = word
  }

  /// Trigger the instance to start crawling the web.
