<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\SiteSetting;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

class EmailSettingController extends Controller
{
    public function index(): View
    {
        return view('admin.email-settings.index', [
            'emailVerificationEnabled' => SiteSetting::emailVerificationEnabled(),
        ]);
    }

    public function update(Request $request): RedirectResponse
    {
        $request->validate([
            'email_verification_enabled' => ['nullable', 'boolean'],
        ]);

        SiteSetting::setValue(
            SiteSetting::EMAIL_VERIFICATION_ENABLED,
            $request->boolean('email_verification_enabled') ? 'on' : 'off'
        );

        return back()->with('success', 'Email verification setting updated.');
    }
}
