<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Controller;
use App\Models\Setting;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

class AiSettingsController extends Controller
{
    public function index(): JsonResponse
    {
        $autoSelect = Setting::where('group', 'ai')->where('key', 'ai_auto_select_enabled')->value('value');
        return response()->json([
            'ai_auto_select_enabled' => $autoSelect === 'true' 
        ]);
    }

    public function update(Request $request): JsonResponse
    {
        $request->validate(['ai_auto_select_enabled' => 'required|boolean']);

        Setting::updateOrCreate(
            ['group' => 'ai', 'key' => 'ai_auto_select_enabled'],
            ['value' => $request->ai_auto_select_enabled ? 'true' : 'false']
        );

        return response()->json(['message' => 'AI settings updated.']);
    }
}