<?php

namespace App\Models;

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

class MexcoFeature extends Model
{
    protected $table = 'mexco_features';

    protected $fillable = [
        'code',
        'name',
        'description',
        'category',
        'is_active',
        'sort_order',
    ];

    protected function casts(): array
    {
        return [
            'is_active' => 'boolean',
        ];
    }

    public function plans(): BelongsToMany
    {
        return $this->belongsToMany(MexcoPlan::class, 'mexco_plan_features', 'feature_id', 'plan_id')
            ->withPivot(['enabled', 'limit_value', 'metadata'])
            ->withTimestamps();
    }

    public function addons(): BelongsToMany
    {
        return $this->belongsToMany(MexcoAddon::class, 'mexco_addon_features', 'feature_id', 'addon_id')
            ->withPivot(['enabled', 'limit_value'])
            ->withTimestamps();
    }

    public function planFeatures(): HasMany
    {
        return $this->hasMany(MexcoPlanFeature::class, 'feature_id');
    }
}
