<?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_renewal_configs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('membership_category_id')->nullable()->constrained()->onDelete('cascade');
            $table->unsignedSmallInteger('renewal_period_months')->default(12);
            $table->boolean('is_default')->default(false);
            $table->date('effective_from');
            $table->date('effective_until')->nullable();
            $table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
            $table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
            $table->timestamps();

            $table->index('is_default');
            $table->index('membership_category_id');
        });
    }

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