<?php

use App\Models\ContentType;
use App\Models\ContentTypeSlugHistory;
use App\Services\ArtworkService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

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

it('resolves historical content type slugs in artwork service content type browsing', function () {
    $contentType = ContentType::query()->create([
        'name' => 'Digital Illustration',
        'slug' => 'digital-illustration',
        'description' => 'Digital illustration uploads',
        'order' => 1,
    ]);

    ContentTypeSlugHistory::query()->create([
        'content_type_id' => $contentType->id,
        'old_slug' => 'digital-art',
    ]);

    $paginator = app(ArtworkService::class)->getArtworksByContentType('digital-art', 24);

    expect($paginator->count())->toBe(0)
        ->and($paginator->items())->toBeArray();
});

it('resolves historical content type slugs in artwork service category path browsing', function () {
    $contentType = ContentType::query()->create([
        'name' => 'Digital Illustration',
        'slug' => 'digital-illustration',
        'description' => 'Digital illustration uploads',
        'order' => 1,
    ]);

    ContentTypeSlugHistory::query()->create([
        'content_type_id' => $contentType->id,
        'old_slug' => 'digital-art',
    ]);

    $rootCategory = $contentType->categories()->create([
        'parent_id' => null,
        'name' => 'Concepts',
        'slug' => 'concepts',
        'description' => null,
        'image' => null,
        'is_active' => true,
        'sort_order' => 0,
    ]);

    $paginator = app(ArtworkService::class)->getArtworksByCategoryPath([
        'digital-art',
        $rootCategory->slug,
    ], 24);

    expect($paginator->count())->toBe(0)
        ->and($paginator->items())->toBeArray();
});