<?php

declare(strict_types=1);

use Builder\Core\Foundation\Concerns\HasBuilderAccess;
use Builder\Core\Foundation\Contracts\BuilderAccessible;

it('interface requires canAccessBuilder method', function (): void {
    $user = new class implements BuilderAccessible
    {
        use HasBuilderAccess;
    };

    expect($user->canAccessBuilder())->toBeTrue();
});

it('interface requires builderPermissions method', function (): void {
    $user = new class implements BuilderAccessible
    {
        use HasBuilderAccess;
    };

    expect($user->builderPermissions())->toBe(['*']);
});

it('canAccessBuilder can be overridden', function (): void {
    $user = new class implements BuilderAccessible
    {
        use HasBuilderAccess;

        public function canAccessBuilder(): bool
        {
            return false;
        }
    };

    expect($user->canAccessBuilder())->toBeFalse();
});

it('builderPermissions can be overridden', function (): void {
    $user = new class implements BuilderAccessible
    {
        use HasBuilderAccess;

        /** @return list<string> */
        public function builderPermissions(): array
        {
            return ['pages.read', 'pages.write'];
        }
    };

    expect($user->builderPermissions())->toBe(['pages.read', 'pages.write']);
});
