<?php
/**
 * Migration class for the 'employees_weekday_time_period_locations' table.
 */

namespace RadiusTheme\RadiusBooking\Databases\Table;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
use RadiusTheme\RadiusBooking\Core\Database\Schema\Blueprint;
use RadiusTheme\RadiusBooking\Abstracts\Migration;
use RadiusTheme\RadiusBooking\Core\Database\Schema\Schema;

/**
 * Class EmployeesWeekdayTimePeriodLocationsTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'employees_weekday_time_period_locations' table.
 */
class EmployeesWeekdayTimePeriodLocationsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up(): void {
		// Rename old long table name to shorter one for MySQL 64-char identifier limit.
		Schema::rename(
			$this->tablePrefix . 'employees_weekday_time_period_locations',
			$this->tablePrefix . 'emp_weekday_tp_locations'
		);

		Schema::create(
			$this->tablePrefix . 'emp_weekday_tp_locations',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedInteger( 'weekday_time_period_id' );
				$table->unsignedInteger( 'location_id' );
				$table->timestamps();
			}
		);
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down(): void {
		Schema::drop( $this->tablePrefix . 'emp_weekday_tp_locations' );
	}
}
