<?php

namespace App\Models;

use CodeIgniter\Model;

class InspectionAnswerModel extends Model
{
    protected $table = 'inspection_answers';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $useAutoIncrement = true;
    protected $protectFields = true;
    protected $allowedFields = [
        'inspection_id', 'item_id',
        'value_bool', 'value_text', 'value_number', 'value_json',
        'comentarios', 'lecturas', 'updated_at',
    ];
    protected $useTimestamps = false;

    public function getMapForInspection(int $inspectionId): array
    {
        $rows = $this->where('inspection_id', $inspectionId)->findAll();
        $map = [];
        foreach ($rows as $r) {
            $map[(int) $r['item_id']] = $r;
        }
        return $map;
    }
}
