<?php
/**
 * Migration class for the 'employees_weekday_time_period' 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 EmployeesWeekdayTimePeriodTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'employees_weekday_time_periods' table.
 */
class EmployeesWeekdayTimePeriodTable 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_periods',
			$this->tablePrefix . 'emp_weekday_time_periods'
		);

		Schema::create(
			$this->tablePrefix . 'emp_weekday_time_periods',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedInteger( 'weekday_id' );
				$table->time( 'start_time' );
				$table->time( 'end_time' );
				$table->timestamps();
			}
		);
	}

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