<?php

namespace App\Models;

use CodeIgniter\Model;

class LogGerbangModel extends Model
{
    protected $table            = 'log_gerbang';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $allowedFields    = ['perizinan_id', 'waktu_scan', 'jenis_scan', 'petugas_id'];

    // Get logs for a specific permit
    public function getByPermit($permitId)
    {
        return $this->select('log_gerbang.*, users.nama_lengkap as petugas_nama')
            ->join('users', 'users.id = log_gerbang.petugas_id')
            ->where('perizinan_id', $permitId)
            ->orderBy('waktu_scan', 'ASC')
            ->findAll();
    }
}
