<?php

use App\Models\StaticDataTable;

/*
|--------------------------------------------------------------------------
| Static Data Table API Tests
|--------------------------------------------------------------------------
|
| Feature tests for the /api/v1/static-data-tables endpoint
|
*/

it('returns a successful response for static data tables index', function () {
    $response = $this->getJson('/api/v1/static-data-tables');

    $response->assertStatus(200);
});

it('returns static data tables with correct structure', function () {
    $response = $this->getJson('/api/v1/static-data-tables');

    $response->assertStatus(200)
        ->assertJsonStructure([
            'data',
            'pagination' => [
                'currentPage',
                'lastPage',
                'perPage',
                'total',
                'count',
                'hasMorePages',
                'nextPageUrl',
                'prevPageUrl',
            ],
        ]);
});

it('can paginate static data tables', function () {
    $response = $this->getJson('/api/v1/static-data-tables?perPage=5&page=1');

    $response->assertStatus(200)
        ->assertJsonPath('pagination.perPage', 5)
        ->assertJsonPath('pagination.currentPage', 1);
});

it('can order static data tables alphabetically', function () {
    $response = $this->getJson('/api/v1/static-data-tables?orderBy=alphabetical');

    $response->assertStatus(200);
});

/*
|--------------------------------------------------------------------------
| Static Data Table Show Endpoint Tests
|--------------------------------------------------------------------------
*/

it('returns a static data table by slug', function () {
    $staticDataTable = StaticDataTable::full()
        ->where('status', 'published')
        ->first();

    if (!$staticDataTable) {
        $this->markTestSkipped('No published static data tables in the database');
    }

    $response = $this->getJson("/api/v1/static-data-tables/{$staticDataTable->lang_slug}");

    $response->assertStatus(200);
});

it('returns 404 for non-existent static data table', function () {
    $response = $this->getJson('/api/v1/static-data-tables/non-existent-slug-12345');

    $response->assertStatus(404);
});
