<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Auth;
use App\Core\Controller;
use App\Core\Csrf;
use App\Core\Permission;
use App\Services\Deployment\EnterpriseDeploymentOrchestratorHttpService;

final class EnterpriseDeploymentOrchestratorController extends Controller
{
    public function index(): void
    {
        Auth::requireLogin();
        Permission::require('updates.view');

        (new EnterpriseDeploymentOrchestratorHttpService())->renderIndex(
            $this,
            $_GET
        );
    }

    public function create(): void
    {
        Auth::requireLogin();
        Permission::require('updates.install');
        Permission::requireSuperAdmin();
        Auth::requireRecentAuthentication();
        Csrf::verify($_POST['_csrf'] ?? null);

        (new EnterpriseDeploymentOrchestratorHttpService())->create(
            $this,
            $_POST
        );
    }

    public function advance(): void
    {
        Auth::requireLogin();
        Permission::require('updates.install');
        Permission::requireSuperAdmin();
        Auth::requireRecentAuthentication();
        Csrf::verify($_POST['_csrf'] ?? null);

        (new EnterpriseDeploymentOrchestratorHttpService())->advance(
            $_POST
        );
    }

    public function status(): void
    {
        Auth::requireLogin();
        Permission::require('updates.view');

        (new EnterpriseDeploymentOrchestratorHttpService())->status(
            $_GET
        );
    }

    public function cancel(): void
    {
        Auth::requireLogin();
        Permission::require('updates.install');
        Permission::requireSuperAdmin();
        Auth::requireRecentAuthentication();
        Csrf::verify($_POST['_csrf'] ?? null);

        (new EnterpriseDeploymentOrchestratorHttpService())->cancel(
            $this,
            $_POST
        );
    }
}
