<?php

declare(strict_types=1);

use App\Models\Artwork;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\actingAs;
use function Pest\Laravel\postJson;

uses(RefreshDatabase::class);

it('returns a disabled payload for the artwork owner while synchronous vision suggestions are off', function (): void {
    config()->set('vision.enabled', true);

    $user = User::factory()->create();
    $artwork = Artwork::factory()->create([
        'user_id' => $user->id,
    ]);

    actingAs($user);

    $response = postJson('/api/uploads/' . $artwork->id . '/vision-suggest?limit=10');

    $response->assertOk()
        ->assertJsonPath('vision_enabled', false)
        ->assertJsonPath('reason', 'disabled')
        ->assertJsonPath('tags', []);
});

it('returns 404 when a non-owner requests upload vision suggestions', function (): void {
    config()->set('vision.enabled', true);

    $owner = User::factory()->create();
    $viewer = User::factory()->create();
    $artwork = Artwork::factory()->create([
        'user_id' => $owner->id,
    ]);

    actingAs($viewer);

    postJson('/api/uploads/' . $artwork->id . '/vision-suggest')
        ->assertStatus(404);
});

it('returns disabled payload when vision suggestions are turned off', function (): void {
    config()->set('vision.enabled', false);

    $user = User::factory()->create();
    $artwork = Artwork::factory()->create([
        'user_id' => $user->id,
    ]);

    actingAs($user);

    postJson('/api/uploads/' . $artwork->id . '/vision-suggest')
        ->assertOk()
        ->assertJsonPath('vision_enabled', false)
        ->assertJsonPath('tags', []);
});