<?php

namespace App\Models;

use CodeIgniter\Model;

class SubscriptionPlanModel extends Model
{
    protected $table         = 'subscription_plans';
    protected $allowedFields = [
        'name', 'slug', 'price_monthly', 'price_yearly', 'candidate_view_limit',
        'contact_reveal_limit', 'resume_download_limit', 'recruiter_limit',
        'job_posting_limit', 'features', 'is_active', 'sort_order',
    ];
    protected $casts = ['features' => 'json'];

    public function activePlans(): array
    {
        return $this->where('is_active', 1)->orderBy('sort_order', 'ASC')->findAll();
    }

    public function findBySlug(string $slug): ?array
    {
        return $this->where('slug', $slug)->first();
    }
}
