<?php

namespace App\Models;

use Core\Model;

class Dosen extends Model
{
    protected $table = 'tb_dosen'; // sesuaikan dengan nama tabel

    /**
     * Cari dosen berdasarkan niy
     */
    public function findByNiy($niy)
    {
        $stmt = $this->query("SELECT * FROM {$this->table} WHERE niy = ?", [$niy]);
        return $stmt->fetch();
    }

    public function updateByNiy($niy, $data)
    {
        $sql = "UPDATE {$this->table} SET 
            nama = ?,
            alamat = ?,
            jenis_kelamin = ?,
            gelar = ?
            WHERE niy = ?";

        return $this->query($sql, [
            $data['nama'],
            $data['alamat'],
            $data['jenis_kelamin'],
            $data['gelar'],
            $niy
        ]);
    }

    /**
     * Ambil semua dosen
     */
    public function all()
    {
        return $this->query("SELECT * FROM {$this->table}")->fetchAll();
    }

    /**
     * Cari dosen berdasarkan username (misal username = niy)
     */
    public function findByUsername($username)
    {
        return $this->findByniy($username);
    }
}
