<?php

use App\Models\TeamMember;

/*
|--------------------------------------------------------------------------
| Team Member API Tests
|--------------------------------------------------------------------------
|
| Feature tests for the /api/v1/team-members endpoint
|
*/

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

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

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

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

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

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

/*
|--------------------------------------------------------------------------
| Team Member Show Endpoint Tests
|--------------------------------------------------------------------------
*/

it('returns a team member by slug', function () {
    $teamMember = TeamMember::full()
        ->where('status', 'published')
        ->first();

    if (!$teamMember) {
        $this->markTestSkipped('No published team members in the database');
    }

    $response = $this->getJson("/api/v1/team-members/{$teamMember->lang_slug}");

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

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

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