<?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()
    {
        Schema::create('product_relations', function (Blueprint $table) {
            $table->id();

            // Required
            $table->foreignId('product_id')
                ->constrained('products')
                ->cascadeOnDelete();

            $table->foreignId('product_category_id')
                ->constrained('product_categories')
                ->cascadeOnDelete();

            $table->foreignId('industry_id')
                ->constrained('industries')
                ->cascadeOnDelete();

            // Nullable fields
            $table->foreignId('product_sub_category_id')
                ->nullable()
                ->constrained('product_sub_categories')
                ->nullOnDelete();

            $table->foreignId('sub_industry_id')
                ->nullable()
                ->constrained('sub_industries')
                ->nullOnDelete();

            $table->timestamps();
        });
    }

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