<?php
class Connection {
    private static $pdo;

    public static function getConnection(): WebbikePDO  {
        if(!isset($pdo)) {
            try {
                $webbikePDO = new WebbikePDO();
            
                if (!$webbikePDO) {
                    throw new Exception("Error while connecting to the database");
                }
                self::$pdo = $webbikePDO;
            } catch (PDOException $e) {
                echo $e->getMessage();
            }
        }

        return self::$pdo;
    }

    public static function getStatement(string $query):PDOStatement  {
        return self::getConnection()->prepare($query);
    }

    /**
     * @deprecated to be removed if the server ever goes online
     */
    public static function executeRawQuery(string $query) : bool  {
        return self::getStatement($query)->execute();
    }

    /**
     * @deprecated to be removed if the server ever goes online
     */
    public static function executeRawQueryWithfetchAll(string $query) : array  {
        $statement = self::getStatement($query);
        $statement->execute();
        return $statement->fetchAll();
    }
}