<?php

use App\MediaLibrary\CustomPathGenerator;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

describe('CustomPathGenerator', function () {
    beforeEach(function () {
        $this->pathGenerator = new CustomPathGenerator;
        $this->media = new Media([
            'id' => 1,
            'model_type' => 'App\Models\MediaMonitoring',
            'model_id' => 1,
            'collection_name' => 'default',
            'name' => 'test-file',
            'file_name' => 'test-file.pdf',
            'mime_type' => 'application/pdf',
            'disk' => 'public',
            'conversions_disk' => 'public',
            'size' => 1024,
            'custom_properties' => [
                'feature' => 'media-monitoring',
                'date' => '2024-01-15',
                'doc_type' => 'document',
            ],
        ]);
    });

    it('generates correct path for media', function () {
        $path = $this->pathGenerator->getPath($this->media);

        expect($path)->toBeString()
            ->and($path)->toContain('media-monitoring')
            ->and($path)->toContain('document')
            ->and($path)->toContain('2024-01-15');
    });

    it('generates correct path for conversions', function () {
        $path = $this->pathGenerator->getPathForConversions($this->media);

        expect($path)->toBeString()
            ->and($path)->toContain('conversions');
    });

    it('generates correct path for responsive images', function () {
        $path = $this->pathGenerator->getPathForResponsiveImages($this->media);

        expect($path)->toBeString()
            ->and($path)->toContain('responsive');
    });

    it('handles missing custom properties gracefully', function () {
        $mediaWithoutProps = new Media([
            'id' => 2,
            'model_type' => 'App\Models\Test',
            'model_id' => 1,
            'collection_name' => 'default',
            'name' => 'test',
            'file_name' => 'test.jpg',
            'custom_properties' => [],
        ]);

        $path = $this->pathGenerator->getPath($mediaWithoutProps);

        expect($path)->toBeString()
            ->and($path)->toContain('misc');
    });
});
