<?php

namespace App\Modules\Academic\Models;

use CodeIgniter\Model;

/**
 * Dapodik rombel string -> internal class_id mapping.
 */
class DapodikRombelMappingModel extends Model
{
    protected $table            = 'dapodik_rombel_mappings';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = 'updated_at';
    protected $allowedFields    = [
        'dapodik_rombel',
        'class_id',
        'last_seen_at',
    ];

    public function getByRombel(string $rombel): ?array
    {
        $row = $this->where('dapodik_rombel', $rombel)->first();
        return $row !== null ? $row : null;
    }
}
