<?php
class Usuario {
    private $db;

    public function __construct($db) {
        $this->db = $db;
    }

    public function obtenerPorUsername($username) {
        $stmt = $this->db->prepare("SELECT * FROM usuarios WHERE username = ? LIMIT 1");
        $stmt->bind_param("s", $username);
        $stmt->execute();
        return $stmt->get_result()->fetch_assoc();
    }

    public function crear($username, $passwordHash, $esSuperadmin = 0, $puedeCrear = 0) {
        $stmt = $this->db->prepare("INSERT INTO usuarios (username, password_hash, es_superadmin, puede_crear_usuarios) VALUES (?, ?, ?, ?)");
        $stmt->bind_param("ssii", $username, $passwordHash, $esSuperadmin, $puedeCrear);
        return $stmt->execute();
    }
}
