<?php
/**
 * Migration class for the 'meeting_types' table.
 *
 * Stores meeting type definitions for the Meeting Booking module.
 *
 * @package RadiusTheme\RadiusBooking
 * @since   1.2.0
 */

namespace RadiusTheme\RadiusBooking\Databases\Table;

use RadiusTheme\RadiusBooking\Core\Database\Schema\Blueprint;
use RadiusTheme\RadiusBooking\Abstracts\Migration;
use RadiusTheme\RadiusBooking\Core\Database\Schema\Schema;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class MeetingTypesTable
 */
class MeetingTypesTable extends Migration {

	/**
	 * Creates the 'meeting_types' table.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'meeting_types',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'employee_id' );
				$table->string( 'name' );
				$table->text( 'description' )->nullable();
				$table->string( 'slug' )->nullable();
				$table->unsignedInteger( 'duration' )->comment( 'Duration in minutes' );
				$table->unsignedInteger( 'buffer_before' )->default( 0 );
				$table->unsignedInteger( 'buffer_after' )->default( 0 );
				$table->double( 'price' )->default( 0.00 );
				$table->string( 'color', 20 )->nullable();
				$table->string( 'location_type', 50 )->default( 'online' );
				$table->string( 'location_details' )->nullable();
				$table->boolean( 'is_active' )->default( 1 );
				$table->boolean( 'requires_confirmation' )->default( 0 );
				$table->unsignedInteger( 'max_bookings_per_day' )->nullable();
				$table->unsignedInteger( 'min_notice_minutes' )->default( 60 );
				$table->unsignedInteger( 'max_advance_days' )->default( 60 );
				$table->json( 'settings' )->nullable()->default( null );
				$table->string( 'picture_full_path' )->nullable();
				$table->string( 'picture_thumb_path' )->nullable();
				$table->timestamps();
				$table->softDeletes();

				$table->index( 'employee_id' );
				$table->index( 'slug' );
				$table->index( 'is_active' );
			}
		);
	}

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