<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ApiAccessTest extends TestCase
{
    use RefreshDatabase;

    public function test_health_endpoint_is_accessible(): void
    {
        $response = $this->get('/health');
        $response->assertSuccessful();
    }

    public function test_api_routes_are_publicly_accessible(): void
    {
        // Test that main API routes are accessible without authentication
        $routes = [
            '/api/v1/articles',
            '/api/v1/dashboard/stats',
            '/api/v1/platform-accounts',
            '/api/v1/platform-channels',
            '/api/v1/feeds',
            '/api/v1/routing',
            '/api/v1/settings',
            '/api/v1/logs',
        ];

        foreach ($routes as $route) {
            $response = $this->get($route);
            $this->assertTrue(
                $response->isSuccessful(),
                "API route {$route} should be publicly accessible"
            );
        }
    }

    public function test_fallback_route_returns_api_message(): void
    {
        $response = $this->get('/nonexistent-route');
        $response->assertStatus(404);
        $response->assertJson([
            'message' => 'Not found. The FFR interface is at /dashboard; API endpoints are under /api/v1.',
            'api_base' => '/api/v1',
        ]);
    }
}
