<?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\Util;

defined( 'ABSPATH' ) || exit;

class Str
{
    public static function snakeToCamel(string $string, bool $capitalizeFirst = false): string
    {
        $str = str_replace('_', ' ', strtolower($string));
        $str = str_replace(' ', '', ucwords($str));

        if (!$capitalizeFirst) {
            $str = lcfirst($str);
        }

        return $str;
    }

    /**
     * Generate a unique code from text (3-5 uppercase chars/digits)
     *
     * Examples:
     * - "Standard Room" → "STDR"
     * - "Deluxe" → "DLX"
     * - "Pokój Deluxe" → "PKDLX"
     * - "Люкс Премиум" → "LXPRM"
     *
     * @param string $input Text to generate code from
     * @param array<string> $existingCodes Already existing codes to avoid collisions
     * @return string Generated code
     */
    public static function generateCode(string $input, array $existingCodes = []): string
    {
        return (new CodeGenerator())->generate($input, $existingCodes);
    }
}
