<?php

namespace App\Traits;

use Exception;
use Illuminate\Support\Facades\Storage;

trait RemoveArchiveS3
{
    /**
     * Delete a file and return a boolean if succeded.
     *
     * @throws \Exception If the file as not found or if the deletion failed.
     */
    public function removeArchiveByPath(string $path): bool
    {
        if (! Storage::exists($path)) {
            return false;
        }

        if (! Storage::delete($path)) {
            throw new Exception('Deletion was not possible');
        }

        return true;
    }
}
