<?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('trainer_rate_history', function (Blueprint $table) {
            $table->id();
            $table->foreignId('academy_id')->constrained('academies');
            $table->foreignId('trainer_id')->constrained('trainers');
            $table->string('field', 30); // which rate field changed: hourly_rate, session_rate, group_rate, player_rate, revenue_share_percent
            $table->string('old_value', 50)->nullable(); // stored as string for flexibility
            $table->string('new_value', 50);
            $table->date('effective_from');
            $table->foreignId('changed_by')->constrained('users');
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index(['trainer_id', 'field', 'effective_from']);
        });
    }

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