<?php

declare(strict_types=1);

use App\Models\Artwork;
use App\Models\User;
use function Pest\Laravel\actingAs;
use function Pest\Laravel\postJson;

it('creates upload drafts as private artworks', function (): void {
    $user = User::factory()->create();

    actingAs($user);

    $response = postJson('/api/artworks', [
        'title' => 'Upload draft test',
        'description' => '<p>Draft body</p>',
        'is_mature' => false,
    ]);

    $response->assertCreated()
        ->assertJsonPath('status', 'draft');

    $artworkId = (int) $response->json('artwork_id');
    $artwork = Artwork::query()->findOrFail($artworkId);

    expect($artwork->visibility)->toBe(Artwork::VISIBILITY_PRIVATE)
        ->and($artwork->is_public)->toBeFalse()
        ->and($artwork->artwork_status)->toBe('draft')
        ->and($artwork->published_at)->toBeNull();
});