<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Addon extends Model
{
    protected $fillable = [
        'slug',
        'name',
        'version',
        'status',
        'description',
        'author',
        'author_url',
        'manifest',
        'installed_at',
        'activated_at',
    ];

    protected function casts(): array
    {
        return [
            'manifest' => 'array',
            'installed_at' => 'datetime',
            'activated_at' => 'datetime',
        ];
    }

    /**
     * Absolute path to this addon's folder on disk. All addon files
     * (PHP, migrations, views, assets) live under here — the AddonManager
     * registers them at boot.
     */
    public function path(string $sub = ''): string
    {
        return base_path('addons/' . $this->slug . ($sub ? '/' . ltrim($sub, '/') : ''));
    }

    public function isActive(): bool
    {
        return $this->status === 'active';
    }
}
