<?php

declare(strict_types=1);

namespace Plugins\Larablog\Membership\Models;

use App\Models\Article;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ArticleMembership extends Model
{
    protected $table = 'article_membership';

    protected $fillable = [
        'article_id',
        'enabled',
        'required_plan_id',
    ];

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

    public function article(): BelongsTo
    {
        return $this->belongsTo(Article::class);
    }

    public function requiredPlan(): BelongsTo
    {
        return $this->belongsTo(MembershipPlan::class, 'required_plan_id');
    }
}
