<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Per-role landing-page overrides. After a user logs in, the first GET /home
 * is intercepted and the user is redirected to the URL configured for the
 * first matching role they hold (admins keep /home unless overridden).
 */
class CreateClcRoleLandingPagesTable extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('clc_role_landing_pages')) {
            Schema::create('clc_role_landing_pages', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('business_id')->index();
                $table->unsignedBigInteger('role_id')->index();
                $table->string('landing_url', 191);
                $table->timestamps();
                $table->unique(['business_id', 'role_id']);
            });
        }
    }

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