<?php
/**
 * Migration class for the 'employees_special_day_time_periods' 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 EmployeesSpecialDayTimePeriodsTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'employees_special_day_time_periods' table.
 */
class EmployeesSpecialDayTimePeriodsTable 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_special_day_time_periods',
			$this->tablePrefix . 'emp_spday_time_periods'
		);

		Schema::create(
			$this->tablePrefix . 'emp_spday_time_periods',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'special_day_id' )->index();
				$table->time( 'start_time' );
				$table->time( 'end_time' );
				$table->timestamps();
			}
		);
	}

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