<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('ordered_songs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('room_session_id')->constrained('room_sessions')->cascadeOnDelete();
            $table->string('from_by')->nullable();
            $table->integer('order_number')->default(0);

            // 歌曲資訊
            $table->foreignId('song_id')->constrained()->cascadeOnDelete();
            $table->string('song_name')->nullable();
            $table->string('artist_name')->nullable();

            
            // 狀態：未播 / 播放中 / 已播 / 刪除
            $table->enum('status', ['NotPlayed', 'Playing', 'Played', 'NoFile', 'Skipped' , 'InsertPlayback'])->default('NotPlayed');

            // 播放流程
            $table->timestamp('ordered_at')->useCurrent(); // 點歌時間
            $table->timestamp('started_at')->nullable();   // 開始播放時間
            $table->timestamp('finished_at')->nullable();  // 播放結束時間

            $table->unique(['room_session_id', 'order_number']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('ordered_songs');
    }
};
