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

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

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