<?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('membership_renewals', function (Blueprint $table) {
            $table->id();
            $table->foreignId('member_id')->constrained()->onDelete('cascade');
            $table->foreignId('certificate_id')->nullable()->constrained('membership_certificates')->onDelete('set null');
            $table->enum('renewal_type', ['manual', 'automatic'])->default('manual');
            $table->timestamp('renewed_at');
            $table->date('previous_end_date')->nullable();
            $table->date('new_end_date');
            $table->foreignId('processed_by')->nullable()->constrained('users')->onDelete('set null');
            $table->timestamps();

            $table->index('member_id');
        });
    }

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