<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

/**
 * Public endpoint that returns configuration values the Flutter app needs
 * to connect to this server.  No authentication required — the URL is the
 * bootstrap value needed before a token exists.
 */
class AppConfigController extends Controller
{
    public function index(): JsonResponse
    {
        return response()->json([
            'server_url'  => config('app.client_url', config('app.url')),
            'version'     => config('app.version', '1.0.0'),
            // Desktop Google OAuth 2.0 credentials (set in admin → Integrations)
            'google_desktop_client_id'     => env('GOOGLE_DESKTOP_CLIENT_ID', ''),
            'google_desktop_client_secret' => env('GOOGLE_DESKTOP_CLIENT_SECRET', ''),
            // Payment method enabled flags (used by Flutter to show/hide payment options)
            'stripe_enabled'  => filter_var(env('STRIPE_ENABLED', 'true'), FILTER_VALIDATE_BOOLEAN),
            'paypal_enabled'  => filter_var(env('PAYPAL_ENABLED', 'true'), FILTER_VALIDATE_BOOLEAN),
            'crypto_enabled'  => filter_var(env('CRYPTO_ENABLED', 'false'), FILTER_VALIDATE_BOOLEAN),
            // [INTEGRATION] Plan limits exposed for client-side pre-validation.
            // Flutter reads these to show upgrade prompts without a server round-trip.
            'plans'       => config('quickropos.plans', [
                'starter' => [
                    'max_products'   => 100,
                    'max_stores'     => 1,
                    'max_staff'      => 1,
                    'max_customers'  => 200,
                ],
                'growth' => [
                    'max_products'   => 1000,
                    'max_stores'     => 3,
                    'max_staff'      => 5,
                    'max_customers'  => 5000,
                ],
                'pro' => [
                    'max_products'   => -1, // unlimited
                    'max_stores'     => -1,
                    'max_staff'      => -1,
                    'max_customers'  => -1,
                ],
            ]),
        ]);
    }
}
