<?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_certificates', function (Blueprint $table) {
            $table->id();
            $table->foreignId('member_id')->constrained()->onDelete('cascade');
            $table->string('certificate_number', 50)->unique();
            $table->date('issue_date');
            $table->date('valid_till_date');
            $table->string('pdf_path')->nullable();
            $table->boolean('is_current')->default(true);
            $table->foreignId('issued_by')->nullable()->constrained('users')->onDelete('set null');
            $table->timestamps();

            $table->index(['member_id', 'is_current']);
        });
    }

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