<?php

declare(strict_types=1);


namespace Plugins\Neatstudio\Membership\Models;

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

class MembershipPlan extends Model
{
    protected $fillable = [
        'name', 'slug', 'description', 'price', 'duration_days', 'permissions', 'active', 'sort',
    ];

    protected $casts = [
        'permissions' => 'array',
        'active' => 'boolean',
    ];

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

    /**
     * 作为可购买实体的展示约定。
     */
    public function payableLabel(): string
    {
        return '会员套餐：'.$this->name;
    }

    public function payableUrl(): ?string
    {
        return route('filament.admin.resources.membership-plans.edit', $this);
    }
}
