<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;

/**
 * @package App\Models
 * @property integer $id
 * @property string $path
 * @property string $lang
 * @property string $type
 *
 * @method string full_path()
 */
class ContractTemplate extends Model
{
    use HasFactory;

    protected $fillable = [
        'path',
        'lang',
        "company",
        'type',
    ];

    public function full_path(): string
    {
        if (!empty($this->path)) {
            if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
                return Storage::temporaryUrl(
                    $this->path,
                    Date::now()->addMinutes(5)
                );
            }
            return '/' . $this->path;
        }

        return asset('storage/' . $this->path);
    }
}
