<?php

namespace App\Modules\HR\Employees\Services;

use App\Modules\HR\Employees\Enums\EmployeeDocumentType;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class EmployeePrivateFileStorage
{
    public function storeUploaded(
        UploadedFile $file,
        int $tenantId,
        int $employeeId,
        EmployeeDocumentType $type,
    ): string {
        $ext = Str::lower($file->getClientOriginalExtension() ?: 'bin');
        $name = $type->value.'-'.Str::uuid()->toString().'.'.$ext;
        $dir = 'tenants/'.$tenantId.'/employees/'.$employeeId;

        return $file->storeAs($dir, $name, ['disk' => 'local']);
    }

    public function exists(string $relativePath): bool
    {
        return Storage::disk('local')->exists($relativePath);
    }

    public function absolutePath(string $relativePath): string
    {
        return Storage::disk('local')->path($relativePath);
    }
}
