<?php

namespace App\Models;

use CodeIgniter\Model;

class JobCategoryModel extends Model
{
    protected $table         = 'job_categories';
    protected $allowedFields = ['name', 'slug', 'parent_id'];
    protected $validationRules = [
        'name' => 'required|max_length[100]',
        'slug' => 'required|alpha_dash|is_unique[job_categories.slug,id,{id}]',
    ];

    public function topLevel(): array
    {
        return $this->where('parent_id', null)->findAll();
    }

    public function childrenOf(int $parentId): array
    {
        return $this->where('parent_id', $parentId)->findAll();
    }
}
