<?php

namespace Modules\Certificate\Http\Controllers;

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

class CertificationSettingsController extends Controller
{
    public function update(Request $request)
    {
        $validated = $request->validate([
            'show_course_certificate' => ['sometimes', 'boolean'],
            'show_course_marksheet' => ['sometimes', 'boolean'],
        ]);

        $system = Setting::where('type', 'system')->firstOrFail();
        $fields = $system->fields ?? [];

        foreach ($validated as $key => $value) {
            $fields[$key] = (bool) $value;
        }

        $system->update(['fields' => $fields]);

        return back()->with('success', 'Certification settings updated successfully.');
    }
}

