<?php

namespace MintyPHP\Http;

class CookieStore implements CookieStoreInterface
{
    public function get(string $name): string
    {
        return (string) ($_COOKIE[$name] ?? '');
    }

    /**
     * @param array<string, mixed> $options
     */
    public function set(string $name, string $value, array $options = []): void
    {
        setcookie($name, $value, $options);
        $_COOKIE[$name] = $value;
    }

    /**
     * @param array<string, mixed> $options
     */
    public function remove(string $name, array $options = []): void
    {
        $removeOptions = ['expires' => time() - 3600, 'path' => '/'];
        foreach ($options as $key => $value) {
            $removeOptions[$key] = $value;
        }

        setcookie($name, '', $removeOptions);
        unset($_COOKIE[$name]);
    }
}
