<?php

namespace App\Services;

class MobileDeepLink
{
    /**
     * @param  array<string, mixed>  $query
     */
    public static function to(string $path, array $query = []): string
    {
        $url = sprintf('%s://%s', self::scheme(), ltrim($path, '/'));
        $queryString = http_build_query($query, '', '&', PHP_QUERY_RFC3986);

        return $queryString === ''
            ? $url
            : "{$url}?{$queryString}";
    }

    private static function scheme(): string
    {
        $scheme = rtrim((string) config('app.mobile_scheme', 'bowly'), ':/');

        return $scheme !== '' ? $scheme : 'bowly';
    }
}
