<?php

declare(strict_types=1);

use App\Support\Seo\SeoFactory;
use Tests\TestCase;

uses(TestCase::class);

it('builds visual artwork item data for gallery collection schemas', function (): void {
    $seo = app(SeoFactory::class)->fromViewData([
        'gallery_type' => 'content-type',
        'page_title' => 'Wallpapers - Skinbase',
        'hero_title' => 'Wallpapers',
        'page_meta_description' => 'Discover desktop and mobile wallpapers from the Skinbase creative community.',
        'page_meta_keywords' => 'wallpapers, skinbase, digital art',
        'page_canonical' => 'https://skinbase.org/wallpapers',
        'current_sort' => 'trending',
        'breadcrumbs' => [
            ['name' => 'Explore', 'url' => '/explore'],
            ['name' => 'Wallpapers', 'url' => '/wallpapers'],
        ],
        'artworks' => collect([
            (object) [
                'id' => 12899,
                'name' => 'Example Wallpaper',
                'slug' => 'example-wallpaper',
                'url' => 'https://skinbase.org/art/12899/example-wallpaper',
                'thumb_url' => 'https://files.skinbase.org/thumbs/example_md.webp',
                'thumb_srcset' => 'https://files.skinbase.org/thumbs/example_lg.webp',
                'uname' => 'CreatorName',
                'username' => 'creatorname',
                'profile_url' => 'https://skinbase.org/@creatorname',
                'published_at' => now()->toAtomString(),
                'width' => 3840,
                'height' => 2160,
                'content_type_name' => 'Wallpapers',
                'published_as_type' => 'user',
                'publisher' => [
                    'type' => 'user',
                    'name' => 'CreatorName',
                    'profile_url' => 'https://skinbase.org/@creatorname',
                ],
            ],
        ]),
    ]);

    expect($seo['json_ld'][0]['@type'] ?? null)
        ->toBe(['CollectionPage', 'ImageGallery'])
        ->and($seo['json_ld'][0]['mainEntity']['@type'] ?? null)->toBe('ItemList')
        ->and($seo['json_ld'][0]['mainEntity']['itemListElement'][0]['item']['@type'] ?? null)->toBe('VisualArtwork')
        ->and($seo['json_ld'][0]['mainEntity']['itemListElement'][0]['item']['url'] ?? null)->toBe('https://skinbase.org/art/12899/example-wallpaper')
        ->and($seo['json_ld'][0]['mainEntity']['itemListElement'][0]['item']['creator']['name'] ?? null)->toBe('CreatorName')
        ->and($seo['json_ld'][0]['mainEntity']['itemListElement'][0]['item']['contentUrl'] ?? null)->toBe('https://files.skinbase.org/thumbs/example_lg.webp')
        ->and($seo['json_ld'][0]['mainEntity']['itemListElement'][0]['item']['encodingFormat'] ?? null)->toBe('image/webp')
        ->and($seo['json_ld'][1]['@type'] ?? null)->toBe('BreadcrumbList');
});