<?php

declare(strict_types=1);

use App\Models\WorldWebStory;
use App\Models\WorldWebStoryPage;
use App\Services\WebStories\WorldWebStoryValidationService;

it('fails validation for missing poster, too few pages, long body, and missing background media', function (): void {
    $story = WorldWebStory::factory()->published()->create([
        'poster_portrait_path' => null,
        'publisher_logo_path' => 'https://cdn.skinbase.org/images/skinbase_logo_96.webp',
    ]);

    WorldWebStoryPage::factory()->for($story, 'story')->create([
        'position' => 1,
        'background_type' => WorldWebStoryPage::BACKGROUND_IMAGE,
        'background_path' => null,
        'background_mobile_path' => null,
        'alt_text' => '',
        'body' => str_repeat('a', 181),
    ]);

    $result = app(WorldWebStoryValidationService::class)->validate($story->fresh('orderedPages'));

    expect($result['valid'])->toBeFalse()
        ->and($result['errors'])->toContain('Poster portrait image is required.')
        ->and($result['errors'])->toContain('A published web story must have at least 5 active pages.')
        ->and(collect($result['errors'])->contains(fn (string $error): bool => str_contains($error, 'body exceeds 180 characters')))->toBeTrue()
        ->and(collect($result['errors'])->contains(fn (string $error): bool => str_contains($error, 'missing required background media')))->toBeTrue();
});