<?php

namespace Tests\Feature;

use App\Models\InvestmentSetting;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class MobileCompatibilityTest extends TestCase
{
    use RefreshDatabase;

    private const ANDROID_UA = 'Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 Chrome/120.0.0.0 Mobile Safari/537.36';

    /**
     * @param  array<string, string>  $headers
     */
    private function mobileHeaders(array $headers = []): array
    {
        return array_merge(['User-Agent' => self::ANDROID_UA], $headers);
    }

    public function test_login_page_renders_for_android(): void
    {
        $this->withHeaders($this->mobileHeaders())
            ->get(route('login'))
            ->assertOk();
    }

    public function test_investor_pages_render_for_android_with_shared_mobile_props(): void
    {
        InvestmentSetting::current();
        $user = User::factory()->create();

        $routes = [
            'dashboard',
            'investments.index',
            'investments.mine',
            'balances.index',
            'balances.movements',
            'balances.wallets',
            'referrals.index',
            'kyc.show',
        ];

        foreach ($routes as $name) {
            $this->actingAs($user)
                ->withHeaders($this->mobileHeaders())
                ->get(route($name))
                ->assertOk()
                ->assertInertia(fn ($page) => $page->where('isMobile', true));
        }
    }

    public function test_admin_pages_render_for_android(): void
    {
        InvestmentSetting::current();
        $admin = User::factory()->admin()->create();

        $routes = [
            'admin.home',
            'admin.users.index',
            'admin.investments.index',
            'admin.platform-accrual.index',
            'admin.investment-settings.edit',
            'admin.notification-settings.edit',
        ];

        foreach ($routes as $name) {
            $this->actingAs($admin)
                ->withHeaders($this->mobileHeaders())
                ->get(route($name))
                ->assertOk()
                ->assertInertia(fn ($page) => $page->where('isMobile', true));
        }
    }
}
