<?php

namespace src\Conexao;

use mysqli;
use Exception;

class Conexao
{
    private $conexao;

    public function __construct()
    {
        // $dominio = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
        // $host = '51.222.153.141';
        // $user = $dominio == 'http://localhost' ? 'pamelave_portal-develop' : 'pamelave_portal';
        // $password = $dominio == 'http://localhost' ? 'YdKCvR3DJ24QuUkDYMSX' : 'EDabBTJb4xqquY2QV2yg';
        // $database = $dominio == 'http://localhost' ? 'pamelave_portal-develop' : 'pamelave_portal';

        // $this->conexao = new mysqli($host, $user, $password, $database);

        // if ($this->conexao->connect_error) {
        //     throw new Exception('Erro de conexão: ' . $this->conexao->connect_error);
        // }

        $config = require 'config.php';
        $env = $config['current_env'];

        $host = $config[$env]['host'];
        $user = $config[$env]['user'];
        $password = $config[$env]['password'];
        $database = $config[$env]['database'];

        $this->conexao = new mysqli($host, $user, $password, $database);

        if ($this->conexao->connect_error) {
            throw new Exception('Erro de conexão: ' . $this->conexao->connect_error);
        }
    }

    public function getConexao()
    {
        return $this->conexao;
    }
}
