<?php

use App\Models\VideoItem;

/*
|--------------------------------------------------------------------------
| Video API Tests
|--------------------------------------------------------------------------
|
| Feature tests for the /api/v1/videos endpoint
|
*/

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

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

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

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

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

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

/*
|--------------------------------------------------------------------------
| Video Show Endpoint Tests
|--------------------------------------------------------------------------
*/

it('returns a video by slug', function () {
    $video = VideoItem::full()
        ->where('status', 'published')
        ->first();

    if (!$video) {
        $this->markTestSkipped('No published videos in the database');
    }

    $response = $this->getJson("/api/v1/videos/{$video->lang_slug}");

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

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

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