<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MembershipPlan extends Model
{
    protected $fillable = [
        'name', 'slug', 'description', 'price', 'purchase_link', 'duration_days', 'trial_days',
        'features', 'perks', 'is_active', 'is_public', 'visible_until', 'sort_order',
        'badge_label', 'accent_color',
    ];

    protected $casts = [
        'features'      => 'array',
        'perks'         => 'array',
        'is_active'     => 'boolean',
        'is_public'     => 'boolean',
        'visible_until' => 'datetime',
        'price'         => 'float',
        'trial_days'    => 'integer',
    ];

    /** Belirli bir perk'in bu planda aktif olup olmadığını döner */
    public function hasPerk(string $key): bool
    {
        return !empty(($this->perks ?? [])[$key]);
    }

    public function subscriptions()
    {
        return $this->hasMany(Subscription::class, 'plan_id');
    }
}
