<?php

declare(strict_types=1);

namespace App\Models\Subscription;

use Hyperf\DbConnection\Model\Model;
use App\Models\User;

class SubscriptionPlan extends Model
{
    protected ?string $table = 'subscription_plans';

    public bool $incrementing = true;

    protected array $fillable = [
        'hashkey',
        'name',
        'description',
        'price',
        'duration_days',
        'expiry_action',
        'active',
        'additional_details',
        'created_by',
        'updated_by',
    ];

    protected array $casts = [
        'active' => 'boolean',
        'price' => 'float',
        'duration_days' => 'integer',
        'additional_details' => 'array',
    ];

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

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
