<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
        public function up(): void
    {
        Schema::create('product_eligibilities', function (Blueprint $table) {
            $table->id();
            //$table->foreignId('product_id')->constrained('products', 'product_id')->onDelete('cascade');
             $table->unsignedBigInteger('product_id'); // fix: explicit FK

            $table->foreign('product_id')
                ->references('product_id')
                ->on('products')
                ->onDelete('cascade');
            $table->enum('member_type', ['self', 'spouse', 'son', 'daughter', 'maternity']);
            $table->string('min_age')->comment('e.g. 18 years or 2 months');
            $table->string('max_age')->comment('e.g. 65 years or Till Marriage');
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->unique(['product_id', 'member_type']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('product_eligibilities');
    }
};
