<?php

declare(strict_types=1);

class ApiToken extends Model
{
    public function isValid(string $token): bool
    {
        $stmt = $this->db->prepare("SELECT id FROM api_tokens WHERE token = :token AND ativo = 1 LIMIT 1");
        $stmt->execute(['token' => $token]);
        return (bool)$stmt->fetch();
    }

    public function listarAtivos(): array
    {
        return $this->db->query("SELECT id, nome, ativo, criado_em FROM api_tokens WHERE ativo = 1 ORDER BY id DESC")->fetchAll();
    }
}
