<?php

namespace App\Models;

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

class ProductVersion extends Model
{
    use HasFactory;

    protected $fillable = [
        'product_id', 'version', 'changelog', 'file_path', 'file_size',
        'checksum', 'channel', 'is_active', 'download_count', 'released_at',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'released_at' => 'datetime',
        'file_size' => 'integer',
    ];

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function downloads()
    {
        return $this->hasMany(Download::class);
    }

    public function scopeStable($query)
    {
        return $query->where('channel', 'stable')->where('is_active', true);
    }
}
