<?php
namespace App\Models;

use Core\Model;
use Core\Database;  // pastikan ini namespace kelas Database kamu
use PDO;

class TokenKKN extends Model
{
    protected $table = 'tb_token';
    protected $kegiatan = 'KKN';

    protected $db;

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

    public function isValid($token)
    {
        $stmt = $this->db->prepare("SELECT * FROM {$this->table} WHERE token = :token AND kegiatan = :kegiatan");
        $stmt->execute([
            'token' => $token,
            'kegiatan' => $this->kegiatan,
        ]);
        return $stmt->fetch(PDO::FETCH_ASSOC) !== false;
    }

    public function delete($token)
    {
        $stmt = $this->db->prepare("DELETE FROM {$this->table} WHERE token = :token");
        return $stmt->execute(['token' => $token]);
    }
}
