<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\JsonResponse;
class ConfigController extends Controller
{
    private function assetUrl(?string $path): string
    {
        if (!$path) return '';
        if (str_starts_with($path, 'http://') || str_starts_with($path, 'https://')) {
            return $path;
        }
        // Convert stored relative path (e.g. "logos/file.png") to a full public URL
        return asset('storage/' . ltrim($path, '/'));
    }

    public function index(): JsonResponse
    {
        return response()->json([
            // Site identity
            'site_name'           => Setting::get('site_name', 'VVmj8 Casino'),
            'site_tagline'        => Setting::get('site_tagline', 'The Ultimate Casino & Sports Betting Platform'),
            'site_logo'           => $this->assetUrl(Setting::get('site_logo', '')),
            'site_favicon'        => $this->assetUrl(Setting::get('site_favicon', '')),
            'site_description'    => Setting::get('site_description', ''),
            'support_email'       => Setting::get('support_email', 'support@vvmj8.com'),
            'support_phone'       => Setting::get('support_phone', '+1 800 VVMJ8'),
            'maintenance_mode'    => Setting::get('maintenance_mode', false),
            'maintenance_message' => Setting::get('maintenance_message', 'Site under maintenance.'),

            // Finance
            'currency'            => Setting::get('default_currency', 'USD'),
            'currency_symbol'     => Setting::get('currency_symbol', '$'),
            'min_deposit'         => Setting::get('global_min_deposit', 10),
            'max_deposit'         => Setting::get('global_max_deposit', 50000),
            'min_withdrawal'      => Setting::get('global_min_withdrawal', 20),
            'max_withdrawal'      => Setting::get('global_max_withdrawal', 10000),
            'deposit_fee_percent' => Setting::get('deposit_fee_percent', 0),
            'withdrawal_fee_percent' => Setting::get('withdrawal_fee_percent', 0),

            // Betting limits
            'min_bet'               => Setting::get('min_bet', 0.10),
            'max_bet'               => Setting::get('max_bet', 10000),
            'max_parlay_legs'       => Setting::get('max_parlay_legs', 10),
            'sports_betting_enabled' => Setting::get('sports_betting_enabled', true),
            'casino_games_enabled'  => Setting::get('casino_games_enabled', true),

            // Registration
            'registration_enabled'        => Setting::get('registration_enabled', true),
            'email_verification_required' => Setting::get('email_verification_required', false),
            'minimum_age'                 => Setting::get('minimum_age', 18),

            // Legal
            'license_number'    => Setting::get('license_number', 'GLH-OCCHKTW0700781-2025'),
            'license_authority' => Setting::get('license_authority', 'Curacao eGaming'),
            'company_name'      => Setting::get('company_name', 'VVmj8 Limited'),
            'terms_url'         => Setting::get('terms_url', ''),
            'privacy_url'       => Setting::get('privacy_url', ''),
            'facebook_url'      => Setting::get('facebook_url', ''),
            'twitter_url'       => Setting::get('twitter_url', ''),
            'instagram_url'     => Setting::get('instagram_url', ''),
            'telegram_url'      => Setting::get('telegram_url', ''),

            // Integrations
            'google_analytics_id' => Setting::get('google_analytics_id', ''),
            'recaptcha_site_key'  => Setting::get('recaptcha_site_key', ''),
            'recaptcha_enabled'   => Setting::get('recaptcha_enabled', false),
        ])->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
          ->header('Pragma', 'no-cache');
    }
}
