<?php

namespace App\Http\Controllers;

use App\Http\Requests\SaveSecuritySettings;
use App\Services\SecuritySettingsService;

class SecuritySettingsController extends Controller
{
    private $securityService;

    public function __construct(SecuritySettingsService $securityService)
    {
        $this->securityService = $securityService;
    }

    public function save(SaveSecuritySettings $request)
    {
        $this->securityService->save($request->secPolicy, [
            'graceperiod' => $request->graceperiod,
            'pwExpiry' => $request->pwExpiry,
            'enforce2fa' => $request->enforce2fa,
            'requirePMC' => $request->requirePMC,
            'enable_registrations' => $request->input('enable_registrations')
        ]);

        return redirect()
            ->back()
            ->with('success', __('Settings saved.'));
    }
}
