<?php
class reset_pw_tokens_model {
    private $db;
    public function __construct() {
        $this->db = database::connect();
    }

    public function get($token) {
        $stmt = $this->db->prepare("SELECT * FROM reset_pw_tokens WHERE token = ?");
        $stmt->execute([$token]);
        return $stmt->fetch(PDO::FETCH_ASSOC);
    }

    public function insert($data) {
        $keys = implode(',', array_keys($data));
        $placeholders = implode(',', array_fill(0, count($data), '?'));
        $stmt = $this->db->prepare("INSERT INTO reset_pw_tokens ($keys) VALUES ($placeholders)");
        return $stmt->execute(array_values($data));
    }

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