<?php
/**
 * OAuth credentials for Dabil social sign-in.
 * ----------------------------------------------------------------------------
 * Paste the values from Google Cloud Console below (see
 * auth/GOOGLE_SIGNIN_SETUP.md for step-by-step instructions).
 *
 * Keep this file private — it holds your client secret. It is required by
 * auth/google.php and auth/google_callback.php.
 */

// From Google Cloud Console > Credentials > OAuth 2.0 Client ID
const GOOGLE_CLIENT_ID     = '887264034741-1hrqgahbk407ubqn1k8aams48vj7clfa.apps.googleusercontent.com';   // e.g. 1234567890-abc123.apps.googleusercontent.com
const GOOGLE_CLIENT_SECRET = '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';   // e.g. GOCSPX-xxxxxxxxxxxxxxxxxxxx

/**
 * The redirect URI Google sends users back to. It MUST exactly match one of
 * the "Authorized redirect URIs" you register in Google Cloud Console.
 *
 * Leave this blank to auto-detect from the current request (recommended — it
 * adapts whether the app is served from the domain root or a /customer path).
 * To pin it explicitly, set e.g.
 *   'https://dabil.com.ng/customer/auth/google_callback.php'
 */
const GOOGLE_REDIRECT_URI = 'https://dabil.com.ng/dabil2/customer/auth/google_callback.php';

/**
 * Build the callback URL. google.php and google_callback.php both live in the
 * same /auth folder, so the callback is simply <this folder>/google_callback.php.
 */
function dabil_google_redirect_uri(): string
{
    if (GOOGLE_REDIRECT_URI !== '') {
        return GOOGLE_REDIRECT_URI;
    }

    // Detect https, honouring common reverse-proxy headers.
    $fwd    = $_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '';
    $https  = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
              || ((int)($_SERVER['SERVER_PORT'] ?? 0) === 443)
              || strtolower($fwd) === 'https';
    $scheme = $https ? 'https' : 'http';

    $host = $_SERVER['HTTP_HOST'] ?? 'localhost';
    $dir  = rtrim(str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '/auth/google.php')), '/');

    return $scheme . '://' . $host . $dir . '/google_callback.php';
}
