<?php
namespace App\Models;

use Core\Database;

class TokenSidang {
    private $db;

    public function __construct() {
        // Ambil koneksi PDO
        $this->db = Database::getConnection();
    }

    // Insert token sidang yang sudah dipakai
    public function insertTokenSkripsi($data) {
        $sql = "INSERT INTO tb_token_s_skripsi (token, nim, tgl_input) VALUES (:token, :nim, :tgl_input)";
        $stmt = $this->db->prepare($sql);
        return $stmt->execute([
            ':token' => $data['token'],
            ':nim' => $data['nim'],
            ':tgl_input' => $data['tgl_input'],
        ]);
    }

    // Cek apakah token sidang sudah ada untuk nim tertentu
    public function getTokenSkripsiByNIM($nim) {
        $sql = "SELECT * FROM tb_token_s_skripsi WHERE nim = :nim";
        $stmt = $this->db->prepare($sql);
        $stmt->execute([':nim' => $nim]);
        return $stmt->fetch();  // fetch = single row
    }
}
