<?php
/**
 * Migration class for the 'customer_bookings' 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 CustomerBookingsTable
 *
 * @package RadiusTheme\RadiusBooking\Databases\Table
 * Migration for creating the 'customer_bookings' table.
 */
class CustomerBookingsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'customer_bookings',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedInteger( 'appointment_id' )->nullable();
				$table->unsignedInteger( 'customer_id' );
				$table->enum( 'status', array( 'pending', 'confirmed', 'completed', 'cancelled' ) );
				$table->double( 'price' )->default( 0.00 );
				$table->integer( 'persons' )->default( 1 );
				$table->unsignedInteger( 'coupon_id' )->nullable();
				$table->string( 'token' );
				$table->json( 'customer_info' )->nullable();
				$table->json( 'custom_info' )->nullable();
				$table->integer( 'utc_offset' )->nullable();
				$table->unsignedBigInteger( 'duration' )->nullable();
				// Snapshot of dynamic pricing applied at booking time (or null if
				// none applied). Stored so admin/views read what was actually paid
				// rather than recalculating against current rules — which would
				// retroactively apply rules created after the booking.
				$table->json( 'dynamic_pricing' )->nullable();
				$table->timestamps();
			}
		);
	}

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