<?php
/**
 * BarberShop hosted shop — database configuration.
 * Copy config/db.local.example.php to config/db.local.php on the server.
 */
declare(strict_types=1);

$local = [];
$localFile = __DIR__ . '/db.local.php';
if (is_readable($localFile)) {
    $loaded = require $localFile;
    $local = is_array($loaded) ? $loaded : [];
}

$cfg = static function (string $key, string $default = '') use ($local): string {
    $v = getenv($key);
    if ($v !== false && $v !== '') {
        return $v;
    }
    return (string) ($local[$key] ?? $default);
};

define('DB_HOST', $cfg('DB_HOST', 'localhost'));
define('DB_PORT', $cfg('DB_PORT', '3306'));
define('DB_USER', $cfg('DB_USER', ''));
define('DB_PASS', $cfg('DB_PASS', ''));
define('DB_NAME', $cfg('DB_NAME', ''));

/**
 * URL prefix. Empty when this package is the subdomain document root
 * (https://YOURSHOP.barber-shop.us/).
 */
define('APP_BASE', rtrim($cfg('APP_BASE', ''), '/'));

/** Shop-local timezone for availability / booking (override in db.local.php) */
define('APP_TIMEZONE', $cfg('APP_TIMEZONE', 'America/New_York'));
date_default_timezone_set(APP_TIMEZONE);

define('APP_ROOT', dirname(__DIR__));
define('UPLOAD_DIR', APP_ROOT . DIRECTORY_SEPARATOR . 'uploads');
define('UPLOAD_URL', (APP_BASE === '' ? '' : APP_BASE) . '/uploads');

/** Locked-demo sandbox only. Hosted shops stay false. */
define('DEMO_MODE', filter_var($cfg('DEMO_MODE', '0'), FILTER_VALIDATE_BOOLEAN));

/** Legacy fallback if an owner row has no password_hash yet. */
define('ADMIN_USER', $cfg('ADMIN_USER', 'admin'));
define('ADMIN_PASS', $cfg('ADMIN_PASS', 'password32'));

/** Stock API placeholders — set keys when integrating */
define('PEXELS_API_KEY', $cfg('PEXELS_API_KEY', ''));
define('UNSPLASH_ACCESS_KEY', $cfg('UNSPLASH_ACCESS_KEY', ''));

/** Reminder delivery — email: log (local proof) or mail (PHP mail()) */
define('REMINDER_MAIL_DRIVER', $cfg('REMINDER_MAIL_DRIVER', 'log'));
define('REMINDER_EMAIL_FROM', $cfg('REMINDER_EMAIL_FROM', 'noreply@localhost'));

/** SMTP (when REMINDER_MAIL_DRIVER=smtp) — Gmail, Outlook, cPanel, etc. */
define('SMTP_HOST', $cfg('SMTP_HOST', ''));
define('SMTP_PORT', $cfg('SMTP_PORT', '587'));
define('SMTP_USER', $cfg('SMTP_USER', ''));
define('SMTP_PASS', $cfg('SMTP_PASS', ''));
define('SMTP_ENCRYPTION', $cfg('SMTP_ENCRYPTION', 'tls')); // tls | ssl | none

/** Optional Twilio — not required; prefer email + carrier email-to-SMS */
define('TWILIO_ACCOUNT_SID', $cfg('TWILIO_ACCOUNT_SID', ''));
define('TWILIO_AUTH_TOKEN', $cfg('TWILIO_AUTH_TOKEN', ''));
define('TWILIO_FROM_NUMBER', $cfg('TWILIO_FROM_NUMBER', ''));
