<?php

namespace Planaday\Database\SQLDatabaseControllers\DayPart;

use ArrayAccess;
use Countable;
use Planaday\Database\Abstraction\SQLQuery\ColumnTypeMap;
use Planaday\Database\Abstraction\SQLQuery\QueryBuilding\SQLColumn;
use Planaday\Database\Abstraction\SQLQuery\SQLFactory;
use Planaday\Database\SQLDatabaseControllers\LinkingTable;
use Planaday\Platform\PlatformAbstraction\DatabaseInterface;
use Traversable;

class DayPartInstructorLink  extends LinkingTable {
	public const DAY_PART_INSTRUCTOR_LINK_TABLE = 'day_part_instructor_link';
	public const INSTRUCTOR_TABLE_PLACEHOLDER = "instructor";
	public const INSTRUCTOR_COLUMN_PLACEHOLDER = "id";

	protected SQLColumn $columnDayPart;
	protected SQLColumn $columnInstructor;

	public function __construct( DatabaseInterface $querySender, SQLFactory $sql, ColumnTypeMap $columnTypeMap ) {
		$this->columnDayPart = $sql->table(
			$querySender->convertTableString(DayPartTable::DAY_PART_TABLE)
		)->getColumn(
			DayPartColumnEnum::ID
		);

		$this->columnInstructor = $sql->table(
			$querySender->convertTableString(self::INSTRUCTOR_TABLE_PLACEHOLDER)
		)->getColumn(
			self::INSTRUCTOR_COLUMN_PLACEHOLDER
		);

		parent::__construct(
			$querySender,
			$sql,
			self::DAY_PART_INSTRUCTOR_LINK_TABLE,
			$this->columnDayPart,
			$this->columnInstructor,
			$columnTypeMap
		);
	}

	/**
	 * @param string $dayPartId
	 *
	 * @return ArrayAccess<int|string, string>&Traversable<int|string, string>&Countable
	 */
	public function getInstructorsForDayPart(string $dayPartId): ArrayAccess&Traversable&Countable {
		return $this->getConnections($dayPartId, $this->columnDayPart, $this->columnInstructor);
	}

	/**
	 * @param string $dayPartId
	 * @param ArrayAccess<int|string, int>&Traversable<int|string, int>&Countable $instructorIds
	 *
	 * @return void
	 */
	public function setInstructorsForDayPart(string $dayPartId, ArrayAccess&Traversable&Countable $instructorIds): void {
		$this->setConnections($dayPartId, $instructorIds, $this->columnDayPart, $this->columnInstructor);
	}
}