<?php

declare(strict_types=1);

use App\Models\AcademyCourse;
use App\Services\Sitemaps\Builders\AcademyCoursesSitemapBuilder;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(Tests\TestCase::class, RefreshDatabase::class);

it('builds sitemap entries only for published academy courses', function (): void {
    config()->set('app.url', 'http://skinbase26.test');
    config()->set('academy.enabled', true);

    AcademyCourse::query()->create([
        'title' => 'Published Academy Course',
        'slug' => 'published-academy-course',
        'excerpt' => 'Visible in sitemap.',
        'access_level' => 'free',
        'difficulty' => 'beginner',
        'status' => 'published',
        'published_at' => now()->subMinute(),
    ]);

    AcademyCourse::query()->create([
        'title' => 'Draft Academy Course',
        'slug' => 'draft-academy-course',
        'excerpt' => 'Hidden from sitemap.',
        'access_level' => 'free',
        'difficulty' => 'beginner',
        'status' => 'draft',
    ]);

    $items = app(AcademyCoursesSitemapBuilder::class)->items();
    $locations = array_map(static fn ($item) => $item->loc, $items);

    expect($locations)
        ->toContain(url('/academy/courses'))
        ->toContain(url('/academy/courses/published-academy-course'))
        ->not->toContain(url('/academy/courses/draft-academy-course'));
});