<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Core\Provider;

defined( 'ABSPATH' ) || exit;

class DBConfig
{
    public static function getName(): string
    {
        return defined('DB_NAME') ? DB_NAME : '';
    }

    public static function getUser(): string
    {
        return defined('DB_USER') ? DB_USER : '';
    }

    public static function getPassword(): string
    {
        return defined('DB_PASSWORD') ? DB_PASSWORD : '';
    }

    public static function getHost(): string
    {
        return self::parseDbHost()['host'];
    }

    public static function getPort(): int
    {
        return (int) self::parseDbHost()['port'];
    }

    private static function parseDbHost(): array
    {
        $host  = defined('DB_HOST') ? DB_HOST : 'localhost';
        $parts = explode(':', $host);
        return [
            'host' => $parts[0],
            'port' => $parts[1] ?? 3306, // by default MySQL port
        ];
    }
}
