<?php

namespace Tests\Feature;

use App\Models\Central\Company;
use App\Models\Central\Plan;
use App\Models\Central\SuperAdmin;
use App\Tenancy\TenantManager;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class CentralCompanyViewTest extends TestCase
{
    use RefreshDatabase;

    public function test_company_view_page_loads_for_existing_record(): void
    {
        $plan = Plan::create(['name' => 'Free', 'slug' => 'free', 'price' => 0, 'features' => []]);
        $company = Company::create([
            'plan_id' => $plan->id, 'slug' => 'viewco', 'name' => 'View Co',
            'status' => 'active',
        ]);

        $admin = SuperAdmin::create([
            'name' => 'Op', 'email' => 'op@example.com',
            'password' => bcrypt('secret'), 'is_active' => true, 'role' => 'owner',
        ]);

        app(TenantManager::class)->setCurrent(null);

        $response = $this->actingAs($admin, 'central')
            ->get("http://service.mir.md/admin/companies/{$company->id}");

        $response->assertStatus(200);
        $response->assertSee('View Co');
    }
}
