<?php

use Illuminate\Support\Facades\Config;

if (! function_exists('ladill_platform_url')) {
    /** Absolute URL on the platform root (ladill.com). */
    function ladill_platform_url(string $path = '/'): string
    {
        return 'https://'.Config::get('app.platform_domain', 'ladill.com').'/'.ltrim($path, '/');
    }
}

if (! function_exists('ladill_account_url')) {
    /** Absolute URL on the unified account portal (account.ladill.com). */
    function ladill_account_url(string $path = '/'): string
    {
        return 'https://'.Config::get('app.account_domain', 'account.ladill.com').'/'.ltrim($path, '/');
    }
}

if (! function_exists('ladill_home_url')) {
    /** Absolute URL on the signed-in product hub (home.ladill.com). */
    function ladill_home_url(string $path = '/'): string
    {
        $platform = (string) Config::get('app.platform_domain', 'ladill.com');

        return 'https://home.'.$platform.'/'.ltrim($path, '/');
    }
}

if (! function_exists('ladill_auth_url')) {
    /** Absolute URL on the identity provider (auth.ladill.com). */
    function ladill_auth_url(string $path = '/'): string
    {
        return 'https://'.Config::get('app.auth_domain', 'auth.ladill.com').'/'.ltrim($path, '/');
    }
}

if (! function_exists('care_money')) {
    /** Format integer minor units as a human currency string (e.g. 12500 → GHS 125.00). */
    function care_money(?int $minor, ?string $currency = null): string
    {
        $currency = $currency ?: config('care.billing.currency', 'GHS');

        return $currency.' '.number_format(((int) $minor) / 100, 2);
    }
}

if (! function_exists('crm_money')) {
    /** @deprecated Use care_money() */
    function crm_money(?int $minor, ?string $currency = null): string
    {
        return care_money($minor, $currency);
    }
}
