<?php

namespace App\Models;

use CodeIgniter\Model;

class ExamEventTeacherModel extends Model
{
    protected $table            = 'exam_event_teachers';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = [
        'exam_event_id', 'teacher_id', 'role', 'max_days'
    ];

    protected $useTimestamps = true;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';

    /**
     * Get roles for a specific exam event keyed by teacher_id
     */
    public function getEventRoles($eventId)
    {
        $rows = $this->where('exam_event_id', $eventId)->findAll();
        $roles = [];
        foreach ($rows as $row) {
            $roles[$row['teacher_id']] = $row['role'];
        }
        return $roles;
    }

    /**
     * Get full teacher data for a specific exam event keyed by teacher_id
     */
    public function getEventTeachersData($eventId)
    {
        $rows = $this->where('exam_event_id', $eventId)->findAll();
        $data = [];
        foreach ($rows as $row) {
            $data[$row['teacher_id']] = [
                'role' => $row['role'],
                'max_days' => (int)$row['max_days']
            ];
        }
        return $data;
    }
}
