<?php

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

class AddRoleAndPermissionsToUsersTable extends Migration
{
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('role', 20)->default('user')->after('is_admin');
            $table->text('admin_permissions')->nullable()->after('role');
        });

        // Existing full admins keep full access under the new scheme.
        \Illuminate\Support\Facades\DB::table('users')->where('is_admin', true)->update(['role' => 'admin']);
    }

    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['role', 'admin_permissions']);
        });
    }
}
