<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class ApplicationFile extends Model
{
    protected $fillable = [
        'application_id',
        'architecture',
        'file_path',
        'file_size',
    ];

    public function application()
    {
        return $this->belongsTo(Application::class);
    }

    public function getFileSizeHumanAttribute()
    {
        $bytes = $this->file_size;
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
        foreach ($units as $unit) {
            if ($bytes < 1024 || $unit === 'TB') {
                return number_format($bytes, $unit === 'B' ? 0 : 1) . ' ' . $unit;
            }
            $bytes /= 1024;
        }
        return number_format($bytes, 1) . ' TB';
    }
}
