<?php

namespace App\Models;

use CodeIgniter\Model;

class ModelGuru extends Model
{
    protected $table      = 'tb_guru';
    protected $primaryKey = 'id_guru';
    protected $returnType = 'array';

    protected $allowedFields = [
        'nip',
        'nama',
        'password',
        'role',
        'walikelas'
    ];

    // Mengambil wali kelas berdasarkan id_kelas
    public function getWaliKelas($id_kelas)
    {
        return $this->where('walikelas', $id_kelas)
            ->first();
    }

    // Mengambil semua Guru BK
    public function getGuruBK()
    {
        return $this->where('role', 'gurubk')
            ->findAll();
    }

    // Mengambil semua Kesiswaan
    public function getKesiswaan()
    {
        return $this->where('role', 'kesiswaan')
            ->findAll();
    }

    // Mengambil guru berdasarkan id
    public function getById($id)
    {
        return $this->find($id);
    }

    // Mengambil guru berdasarkan NIP
    public function getByNip($nip)
    {
        return $this->where('nip', $nip)
            ->first();
    }
}
