<?php

namespace SugarCalendarBookings\Integrations\CalendarEvents;

/**
 * Diff between existing calendar event links and currently deliverable connections.
 *
 * Produced by EventLinkDiffer. Consumed by CalendarEventDispatcher to decide
 * which provider calls (push, update, delete) to make.
 *
 * @since 1.5.0
 */
class EventLinkDiff {

	/**
	 * Connections that need an event pushed, paired with their target provider slug.
	 *
	 * @since 1.5.0
	 *
	 * @var array<int, array{slug: string, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	private array $to_push;

	/**
	 * Existing links whose connection is still deliverable, paired with the live connection.
	 *
	 * @since 1.5.0
	 *
	 * @var array<int, array{link: EventLink, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	private array $to_update;

	/**
	 * Existing links whose connection is no longer deliverable, paired with the live connection.
	 *
	 * @since 1.5.0
	 *
	 * @var array<int, array{link: EventLink, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	private array $to_delete;

	/**
	 * Existing links whose provider isn't currently registered; preserved untouched for later reconciliation.
	 *
	 * @since 1.5.0
	 *
	 * @var EventLink[]
	 */
	private array $orphan_keep;

	/**
	 * Constructor.
	 *
	 * @since 1.5.0
	 *
	 * @param array       $to_push     Pending push entries.
	 * @param array       $to_update   Pending update entries.
	 * @param array       $to_delete   Pending delete entries.
	 * @param EventLink[] $orphan_keep Orphan links preserved untouched.
	 */
	public function __construct(
		array $to_push,
		array $to_update,
		array $to_delete,
		array $orphan_keep
	) {

		$this->to_push     = array_values( $to_push );
		$this->to_update   = array_values( $to_update );
		$this->to_delete   = array_values( $to_delete );
		$this->orphan_keep = array_values( $orphan_keep );
	}

	/**
	 * Get pending push entries.
	 *
	 * @since 1.5.0
	 *
	 * @return array<int, array{slug: string, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	public function to_push(): array {

		return $this->to_push;
	}

	/**
	 * Get pending update entries.
	 *
	 * @since 1.5.0
	 *
	 * @return array<int, array{link: EventLink, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	public function to_update(): array {

		return $this->to_update;
	}

	/**
	 * Get pending delete entries.
	 *
	 * @since 1.5.0
	 *
	 * @return array<int, array{link: EventLink, connection: \SugarCalendarBookings\Integrations\OAuthRelay\OAuthConnectionModel}>
	 */
	public function to_delete(): array {

		return $this->to_delete;
	}

	/**
	 * Get orphan links to keep untouched.
	 *
	 * @since 1.5.0
	 *
	 * @return EventLink[]
	 */
	public function orphan_keep(): array {

		return $this->orphan_keep;
	}
}
