<?php

/* Titan © TakfeDev (MKJUEL). All Rights. */

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Controller;
use App\Services\Admin\SettingsService;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;

class CodeInjectionController extends Controller
{
    protected $settingsService;

    public function __construct(SettingsService $settingsService)
    {
        $this->settingsService = $settingsService;
    }

    public function index(): JsonResponse
    {
        $data = $this->settingsService->getGroup('scripts');
        return response()->json([
            'header_code' => $data['header_code'] ?? '',
            'footer_code' => $data['footer_code'] ?? '',
        ]);
    }

    public function update(Request $request): JsonResponse
    {
        $data = $request->only(['header_code', 'footer_code']);

        $this->settingsService->updateGroup('scripts', $data);

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