<?php
require '../db.php';
require '../functions.php';

header('Content-Type: application/json');
$villager = requireVillagerToken($pdo);

try {
    $stmt = $pdo->prepare("UPDATE villager SET apitoken = NULL WHERE id = ?");
    $stmt->execute([$villager['id']]);

    logActivity($pdo, 'villager', $villager['id'], 'logout', 'villager', $villager['id'], 'Villager logged out of app');

    jsonOut(true, 'Logged out successfully');
} catch (Exception $e) {
    logDebug('[api_logout] ' . $e->getMessage());
    jsonOut(false, 'Something went wrong. Please try again.');
}
