<?php

declare(strict_types=1);

use Builder\Core\Tests\BuilderTestUser;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Schema;

final class NonBuilderUser extends Authenticatable
{
    protected $table = 'users';

    protected $guarded = [];
}

beforeEach(function (): void {
    Schema::create('users', function ($table): void {
        $table->id();
        $table->string('name')->nullable();
        $table->string('email')->nullable();
        $table->string('password')->nullable();
        $table->timestamps();
    });
});

it('denies access to non-builder user', function (): void {
    $user = NonBuilderUser::create(['name' => 'Regular', 'email' => 'user@test.com', 'password' => 'x']);

    $this->actingAs($user)
        ->get(route('builder.dashboard'))
        ->assertStatus(403);
});

it('allows access to builder user', function (): void {
    $user = BuilderTestUser::create(['name' => 'Admin', 'email' => 'admin@test.com', 'password' => 'x']);

    $this->actingAs($user)
        ->get(route('builder.dashboard'))
        ->assertStatus(200);
});
