<?php


namespace App\Services\MediaLibrary;


use DateTimeInterface;
use Illuminate\Support\Str;
use Spatie\MediaLibrary\Support\UrlGenerator\BaseUrlGenerator;

class MediaLibraryCustomUrlGenerator extends BaseUrlGenerator {

    /**
     * @return string
     */
    public function getUrl(): string{
        $url = $this->getDisk()->url($this->getPathRelativeToRoot());
        //$url = str_replace("storage/","",$url);
        $url = str_replace("public/","",$url);
        return $this->versionUrl($url);
    }

    /**
     * @param DateTimeInterface $expiration
     * @param array $options
     * @return string
     */
    public function getTemporaryUrl(DateTimeInterface $expiration, array $options = []): string{
        return $this->getDisk()->temporaryUrl($this->getPathRelativeToRoot(), $expiration, $options);
    }

    /**
     * @return string
     */
    public function getPath(): string{
        return $this->getRootOfDisk().$this->getPathRelativeToRoot();
    }

    /**
     * @return string
     */
    public function getResponsiveImagesDirectoryUrl(): string{
        $path = $this->pathGenerator->getPathForResponsiveImages($this->media);
        return Str::finish($this->getDisk()->url($path), '/');
    }
}
