import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import src.models.UserModel;
import src.models.squirrel.Database;
import src.models.squirrel.ModelManager;

public class Main {
    public static void main(String[] args) throws SQLException {
        ModelManager.initializeModels();
        Database.migrate = conn -> src.Migration.run(conn);
        Database.getConnection();

        UserModel userModel = ModelManager.get(UserModel.class);
        List<UserModel> users = userModel.where(java.util.Collections.emptyMap());
        for (UserModel user : users) {
            user.set("name", user.get("name") + " Updated");
            user.save();
            System.out.println(user);
        }

        Connection conn = Database.getConnection();
        // Example: Run a simple SQL query
        try (var stmt = conn.createStatement();
             var rs = stmt.executeQuery("SELECT COUNT(*) AS user_count FROM users")) {
            if (rs.next()) {
                int userCount = rs.getInt("user_count");
                System.out.println("Total users: " + userCount);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        Database.close();
    }
}
