<?php

namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;

/**
 * The single guard rail described in 08-installation-workflow.md: once
 * writable/install.lock exists, the entire /install/* route group becomes
 * unreachable — prevents re-running the installer against a live system.
 * Applied as a route-group filter on 'install' in Routes.php.
 */
class InstallGuard implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        if (file_exists(WRITEPATH . 'install.lock')) {
            return redirect()->to('/')->with('info', 'This application is already installed.');
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {
        // no-op
    }
}
