<?php

use App\Enums\IssueSentiment;
use App\Models\Classification;
use App\Models\Location;
use App\Models\MediaMonitoring;
use App\Models\SubClassification;
use App\Models\SubLocation;
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('issue_management', function (Blueprint $table) {
            $table->id();
            $table->foreignIdFor(Location::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(SubLocation::class)->nullable()->constrained()->nullOnDelete();
            $table->foreignIdFor(Classification::class)->constrained()->cascadeOnDelete();
            $table->foreignIdFor(SubClassification::class)->nullable()->constrained()->nullOnDelete();
            $table->foreignIdFor(MediaMonitoring::class)->constrained()->cascadeOnDelete();
            $table->enum('issue', [IssueSentiment::values()])->comment(IssueSentiment::comment());
            $table->enum('response', [IssueSentiment::values()])->comment(IssueSentiment::comment());
            $table->text('description');
            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
            $table->softDeletes();
        });
    }

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