<?php

use App\Models\ProductManagement\Product;
use App\Models\ProductManagement\Review;
use App\Models\UserManagement\Customer;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create((new Review)->getTable(), function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(Customer::class,"customer_id")
                ->constrained((new Customer)->getTable(), (new Customer)->getKeyName())
                ->cascadeOnUpdate()->cascadeOnDelete()
                ->comment("[FK] Le client");

            $table->foreignIdFor(Product::class,'product_id')
                ->constrained((new Product)->getTable(), (new Product)->getKeyName())
                ->cascadeOnUpdate()->cascadeOnDelete()
                ->comment("[FK]");

            $table->text('content');
            $table->boolean('active')->default(false);
            $table->unsignedTinyInteger('rating');
            $table->string('ip_address')->nullable();
            $table->timestamps();
            $table->softDeletes();
        });
    }

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