<?php
// config/config.php

// Load environment variables from .env
if (file_exists(__DIR__ . '/../.env')) {
    $lines = file(__DIR__ . '/../.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    foreach ($lines as $line) {
        if (strpos(trim($line), '#') === 0) continue;
        if (strpos($line, '=') !== false) {
            list($name, $value) = explode('=', $line, 2);
            $name = trim($name);
            $value = trim($value);
            if (preg_match('/^(["\'])(.*)\\1$/', $value, $matches)) {
                $value = $matches[2];
            }
            if (!defined($name)) {
                define($name, $value);
            }
        }
    }
}

// Define paths
define('ROOT_PATH', dirname(__DIR__));
define('APP_PATH', ROOT_PATH . '/app');
define('CONFIG_PATH', ROOT_PATH . '/config');
define('STORAGE_PATH', ROOT_PATH . '/storage');
define('PUBLIC_PATH', ROOT_PATH . '/public');
define('UPLOAD_PATH', PUBLIC_PATH . '/uploads');
define('DATABASE_PATH', ROOT_PATH . '/database');

// Set defaults if not in .env
if (!defined('APP_NAME')) define('APP_NAME', 'rentidium');
if (!defined('APP_SLOGAN')) define('APP_SLOGAN', "Nigeria's Premier Rental Marketplace");
if (!defined('APP_TIMEZONE')) define('APP_TIMEZONE', 'Africa/Lagos');
if (!defined('SESSION_LIFETIME')) define('SESSION_LIFETIME', 3600);
if (!defined('ITEMS_PER_PAGE')) define('ITEMS_PER_PAGE', 12);

if (!defined('ORDER_EMAIL')) define('ORDER_EMAIL', 'order@rentidium.ng');
if (!defined('ADMIN_EMAIL')) define('ADMIN_EMAIL', 'admin@rentidium.ng');

// Payment callback URLs (computed values, not raw .env strings)
define('PAYSTACK_CALLBACK_URL', APP_URL . '/payment-callback.php');
define('FLW_CALLBACK_URL', APP_URL . '/payment-callback.php');

// ── Dojah KYC ─────────────────────────────────────────────────────
// DOJAH_SECRET_KEY, DOJAH_ENV, and the three DOJAH_WIDGET_* constants
// are all loaded automatically from .env by the loader above.
// Only DOJAH_BASE_URL is defined here because it is computed from DOJAH_ENV.
define('DOJAH_BASE_URL',
    DOJAH_ENV === 'live'
        ? 'https://api.dojah.io'
        : 'https://sandbox.dojah.io'
);

// KYC callback URL — where Dojah redirects after widget completion.
// Dojah will append ?verification_id=xxx to this URL automatically.
// This must match the callback URL you set in your Dojah dashboard for each widget.
define('KYC_CALLBACK_URL', APP_URL . '/kyc-callback.php');

// Set timezone
date_default_timezone_set(APP_TIMEZONE);