<?php

namespace App\Modules\Stock;

use App\Contracts\ExternalMediaUrlProvider;
use Illuminate\Support\Str;
use Mtc\ContentManager\Contracts\Media;

class Motors implements ExternalMediaUrlProvider
{
    public function url(Media $media, string $size): string
    {
        // Image format changed: src may now hold the full URL rather than a partial path.
        // Only prepend the resizer prefix when it isn't already an absolute URL.
        if (Str::startsWith($media->src, ['http://', 'https://'])) {
            return $media->src;
        }

        return "https://origin-resizer.images.autoexposure.co.uk/" . ltrim($media->src, '/');
    }
}
