<?php

namespace Tests\Feature\Wallet;

use App\Models\User;
use App\Support\InstallationState;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\File;
use Tests\TestCase;

class WalletPageTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();

        File::put(app(InstallationState::class)->lockPath(), now()->toIso8601String());

        config([
            'product_owner.license_key' => 'FREE-TEST-0000-0000',
            'product_owner.installation_id' => '00000000-0000-0000-0000-000000000001',
        ]);

        $this->seed(\Database\Seeders\RoleAndPermissionSeeder::class);
    }

    public function test_wallet_page_is_accessible_with_permission(): void
    {
        $user = User::factory()->create();
        $user->assignRole(config('permissions.super_admin_role', 'Super Admin'));

        $this->actingAs($user)
            ->get(route('wallet.index'))
            ->assertOk()
            ->assertSee('Transaction Ledger', false)
            ->assertDontSee('Available Modules', false);
    }

    public function test_marketplace_page_no_longer_shows_wallet_ledger(): void
    {
        $user = User::factory()->create();
        $user->assignRole(config('permissions.super_admin_role', 'Super Admin'));

        $this->actingAs($user)
            ->get(route('marketplace.index'))
            ->assertOk()
            ->assertDontSee('Wallet Ledger', false)
            ->assertSee('Available Modules', false);
    }
}
