<?php
require_once 'backend/models/Timer.php';
require_once 'backend/config/database.php';

$database = new Database();
$timer = new Timer($database->getConnection());

$timer->id = 3;
echo "Attempting to stop timer...\n";

try {
    $timer->end_time = date('Y-m-d H:i:s');
    $query = "UPDATE timers SET end_time = NOW(), updated_at = NOW() WHERE id = ? AND end_time IS NULL";
    $stmt = $timer->conn->prepare($query);
    $stmt->execute([$timer->id]);
    
    if ($stmt->rowCount() > 0) {
        echo json_encode(['success' => true, 'message' => 'Timer stopped successfully']);
    } else {
        echo json_encode(['success' => false, 'message' => 'Timer not found']);
    }
} catch (Exception $e) {
    echo json_encode(['error' => 'Failed to stop timer: ' . $e->getMessage()]);
}
