<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('serenata_status_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('organization_id')->constrained('organizations')->cascadeOnDelete();
            $table->foreignId('serenata_id')->constrained('serenatas')->cascadeOnDelete();
            $table->foreignId('changed_by_user_id')->constrained('users')->cascadeOnDelete();
            $table->string('from_service_status', 40)->nullable();
            $table->string('to_service_status', 40)->nullable();
            $table->string('from_payment_status', 20)->nullable();
            $table->string('to_payment_status', 20)->nullable();
            $table->text('note')->nullable();
            $table->timestamps();

            $table->index(['organization_id', 'serenata_id']);
            $table->index(['serenata_id', 'created_at']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('serenata_status_histories');
    }
};
