<?php
/**
 * Migration class for the 'event_ticket_types' table.
 *
 * @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 EventTicketTypesTable
 */
class EventTicketTypesTable extends Migration {

	/**
	 * Creates the 'event_ticket_types' table.
	 *
	 * @return void
	 */
	public function up(): void {
		Schema::create(
			$this->tablePrefix . 'event_ticket_types',
			function ( Blueprint $table ) {
				$table->id();
				$table->unsignedBigInteger( 'event_id' );
				$table->string( 'name' );
				$table->text( 'description' )->nullable();
				$table->string( 'ticket_type', 50 )->default( 'paid' );
				$table->double( 'price' )->default( 0.00 );
				$table->unsignedInteger( 'capacity' )->nullable();
				$table->unsignedInteger( 'quantity_sold' )->default( 0 );
				$table->dateTime( 'sale_start_date' )->nullable();
				$table->dateTime( 'sale_end_date' )->nullable();
				$table->unsignedInteger( 'min_per_order' )->default( 1 );
				$table->unsignedInteger( 'max_per_order' )->default( 10 );
				$table->boolean( 'is_active' )->default( 1 );
				$table->unsignedInteger( 'sort_order' )->default( 0 );
				$table->timestamps();

				$table->index( 'event_id' );
				$table->index( 'is_active' );
			}
		);
	}

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