<?php

namespace SugarCalendarBookings\Integrations\CalendarEvents;

use WP_Error;

/**
 * Result of a CalendarEventDispatcher::dispatch() call.
 *
 * Carries the resulting EventLinkCollection (to persist) and per-target errors
 * keyed by "{provider_slug}:{connection_id}".
 *
 * @since 1.5.0
 */
class DispatchResult {

	/**
	 * Calendar event links resulting from dispatch, ready to persist.
	 *
	 * @since 1.5.0
	 *
	 * @var EventLinkCollection
	 */
	private EventLinkCollection $new_links;

	/**
	 * Errors that occurred during dispatch, keyed by "{provider_slug}:{connection_id}".
	 *
	 * @since 1.5.0
	 *
	 * @var array<string, WP_Error>
	 */
	private array $errors;

	/**
	 * Constructor.
	 *
	 * @since 1.5.0
	 *
	 * @param EventLinkCollection     $new_links Resulting links collection.
	 * @param array<string, WP_Error> $errors    Errors keyed by "{slug}:{connection_id}".
	 */
	public function __construct( EventLinkCollection $new_links, array $errors = [] ) {

		$this->new_links = $new_links;
		$this->errors    = $errors;
	}

	/**
	 * Get the resulting EventLinkCollection.
	 *
	 * @since 1.5.0
	 *
	 * @return EventLinkCollection
	 */
	public function new_links(): EventLinkCollection {

		return $this->new_links;
	}

	/**
	 * Get errors keyed by "{provider_slug}:{connection_id}".
	 *
	 * @since 1.5.0
	 *
	 * @return array<string, WP_Error>
	 */
	public function errors(): array {

		return $this->errors;
	}
}
