<?php

namespace App\Modules\Admin\Tenancy\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Module extends Model
{
    protected $fillable = [
        'slug',
        'name',
        'description',
        'icon',
        'route_name',
        'category',
        'is_core',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'is_core' => 'boolean',
    ];

    public function plans(): BelongsToMany
    {
        return $this->belongsToMany(Plan::class, 'plan_module')->withTimestamps();
    }

    public function scopeActive(Builder $query): Builder
    {
        return $query->where('is_active', true);
    }
}
