<?php

declare(strict_types=1);

class Session
{
    public static function set(string $key, $value): void
    {
        $_SESSION[$key] = $value;
    }

    public static function get(string $key, $default = null)
    {
        return isset($_SESSION[$key]) ? $_SESSION[$key] : $default;
    }

    public static function forget(string $key): void
    {
        unset($_SESSION[$key]);
    }

    public static function flash(string $key, $value): void
    {
        if (!isset($_SESSION['_flash']) || !is_array($_SESSION['_flash'])) {
            $_SESSION['_flash'] = array();
        }
        $_SESSION['_flash'][$key] = $value;
    }

    public static function getFlash(string $key)
    {
        $value = isset($_SESSION['_flash'][$key]) ? $_SESSION['_flash'][$key] : null;
        unset($_SESSION['_flash'][$key]);
        return $value;
    }
}
