<?php

namespace Tests\Tenant;

use Illuminate\Support\Facades\Schema;
use Mtc\ContentManager\Models\Media;
use Tests\TenantTestCase;

/**
 * AUTO-1401: the legacy_structure column and the legacy path branch it
 * controlled have been removed. All media now resolves via the new
 * date-partitioned structure where the dimension folder replaces "/orig/".
 */
class DropLegacyStructureFromMediaTest extends TenantTestCase
{
    public function testLegacyStructureColumnIsDropped(): void
    {
        $this->assertFalse(
            Schema::hasColumn('media', 'legacy_structure'),
            'The legacy_structure column should no longer exist on the media table.'
        );
    }

    public function testThumbnailPathUsesNewStructureWithoutLegacyColumn(): void
    {
        $media = Media::factory()->create([
            'type' => 'image',
            'src' => 'image.webp',
            'path' => 'tenant/2025-04/orig/ab/abcd',
        ]);

        // default_thumbnail_size is 300x300, so /orig/ is swapped for /300x300/.
        $this->assertSame('tenant/2025-04/300x300/ab/abcd/image.webp', $media->thumbnailFilePath());
        $this->assertStringNotContainsString('/orig/', $media->thumbnailFilePath());
    }

    public function testOriginalFilePathIsIndependentOfDimensions(): void
    {
        $media = Media::factory()->create([
            'type' => 'image',
            'src' => 'image.webp',
            'path' => 'tenant/2025-04/orig/ab/abcd',
        ]);

        $this->assertSame('tenant/2025-04/orig/ab/abcd/image.webp', $media->getOriginalFilePath());
    }
}
