<?php

namespace App\Models\Environments;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Update extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'updates';

    const MATURITY_OPTIONS = [
        50  => 'MATURITY_ALPHA',
        100 => 'MATURITY_BETA',
        150 => 'MATURITY_RC',
        200 => 'MATURITY_STABLE'
    ];

    protected $fillable = [
        'environment_id',
        'version',
        'release',
        'maturity',
        'url',
        'download',
        'downloadmd5',
    ];

    protected $casts = [
        'maturity' => 'integer',
    ];

    protected $appends = ['maturityname'];

    public function getMaturitynameAttribute()
    {
        return self::MATURITY_OPTIONS[$this->maturity] ?? $this->maturity;
    }

    public function environment()
    {
        return $this->belongsTo(Environment::class);
    }
}

