<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SettingsController extends Controller
{
    public function index()
    {
        $settings = [
            'app_name' => \App\Models\SystemSetting::get('app_name', 'Enterprise FMS'),
            'smtp_host' => \App\Models\SystemSetting::get('smtp_host', 'smtp.enterprise.com'),
            'smtp_port' => \App\Models\SystemSetting::get('smtp_port', '587'),
        ];
        return view('settings.index', compact('settings'));
    }

    public function update(Request $request)
    {
        foreach ($request->except('_token') as $key => $value) {
            \App\Models\SystemSetting::set($key, $value);
        }
        
        return redirect()->back()->with('success', 'Settings updated successfully!');
    }
}
