<?php

namespace App\Models;

use CodeIgniter\Model;

class SystemModuleModel extends Model
{
    protected $table         = 'system_modules';
    protected $primaryKey    = 'id';
    protected $returnType    = 'array';
    protected $useTimestamps = false;

    protected $allowedFields = [
        'module_key',
        'is_enabled',
        'updated_by',
        'updated_at',
    ];

    /**
     * @return array<string, bool> module_key => is_enabled
     */
    public function enabledMap(): array
    {
        $rows = $this->findAll();
        $map  = [];

        foreach ($rows as $row) {
            $map[$row['module_key']] = (bool) $row['is_enabled'];
        }

        return $map;
    }
}
