<?php

namespace App\Http\Controllers\Api\V1;

use App\Domain\Shared\Models\SystemSetting;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class AppConfigController extends Controller
{
    public function index(): JsonResponse
    {
        $academy = app('current_academy');

        if (!$academy) {
            return response()->json([
                'error' => 'academy_not_found',
                'message' => 'لا يمكن تحديد الأكاديمية',
            ], 404);
        }

        return response()->json([
            'academy' => [
                'name' => $academy->name,
                'name_ar' => $academy->name_ar,
                'logo_url' => $academy->logo_path ? asset('storage/' . $academy->logo_path) : null,
                'phone' => $academy->phone,
                'email' => $academy->email,
            ],
            'theme' => [
                'primary_color' => SystemSetting::get('app_primary_color', '#1e40af'),
                'accent_color' => SystemSetting::get('app_accent_color', '#f59e0b'),
            ],
            'features' => [
                'shop' => (bool) SystemSetting::get('app_features_shop', true),
                'events' => (bool) SystemSetting::get('app_features_events', true),
                'chat' => (bool) SystemSetting::get('app_features_chat', false),
                'online_payment' => (bool) SystemSetting::get('app_features_online_payment', false),
            ],
            'auth' => [
                'otp_mode' => SystemSetting::get('auth_otp_mode', 'demo'),
            ],
            'app' => [
                'min_version' => SystemSetting::get('app_min_version', '1.0.0'),
                'maintenance_mode' => (bool) SystemSetting::get('app_maintenance_mode', false),
                'maintenance_message' => SystemSetting::get('app_maintenance_message', ''),
            ],
        ]);
    }
}
