<?php
require_once __DIR__ . '/../config/database.php';

class TaskController {

    private $conn;

    public function __construct() {
        $this->conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
        if ($this->conn->connect_error) {
            die("Error de conexión: " . $this->conn->connect_error);
        }
    }

    public function getPendingTasks() {
        $result = $this->conn->query("SELECT * FROM tasks WHERE completed = FALSE");
        $tasks = [];
        while ($row = $result->fetch_assoc()) {
            $tasks[] = $row;
        }
        return $tasks;
    }

    public function completeTask($taskId) {
        $this->conn->query("UPDATE tasks SET completed = TRUE WHERE id = $taskId");
    }
}
?>