<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\IntegrationSetting;
use Illuminate\Http\Request;
use Inertia\Inertia;
use function Termwind\render;

class IntegrationController extends Controller
{
    public function edit()
    {
        return Inertia::render('1c/Integration/Edit', [
            'settings' => IntegrationSetting::oneC()
        ]);
    }

    public function update(Request $request)
    {
        $data = $request->validate([
            'url' => 'nullable|string',
            'token' => 'nullable|string',
            'enabled' => 'boolean',
        ]);

        $settings = IntegrationSetting::oneC();
        $settings->update($data);

        return back()->with('success', 'Настройки обновлены');
    }
}
