<?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('user_feedbacks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('type', 32); // bug | feedback | rating
            $table->string('subject', 255)->nullable();
            $table->text('body')->nullable();
            $table->unsignedTinyInteger('rating')->nullable(); // 1–5 for rating type
            $table->string('app_version', 64)->nullable();
            $table->string('platform', 32)->nullable();
            $table->json('meta')->nullable();
            $table->timestamps();

            $table->index(['type', 'created_at']);
        });
    }

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