<?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('route_slugs', function (Blueprint $table) {
            $table->id();
            // PRC-554 — Locale-aware URL slug mapping (N-dil dynamic).
            // Each row = "this route in this language has this slug".
            // Boot-time loaded ve LocalizedRouteRegistrar tarafından route compile'a feed edilir.
            $table->string('route_name', 128);        // 'store.basket.index'
            $table->unsignedBigInteger('language_id');
            $table->string('slug', 128);              // 'sepet'
            $table->timestamps();

            $table->foreign('language_id')
                  ->references('id')->on('languages')
                  ->onDelete('cascade');

            // (route_name, language_id) unique: aynı dilde aynı route iki slug'a sahip olamaz.
            $table->unique(['route_name', 'language_id']);
            // slug globally unique: Laravel routing path conflict olmasın.
            $table->unique('slug');
        });
    }

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