<?php

declare(strict_types=1);

namespace KupShop\MetricsBundle\StatusProviders;

use KupShop\KupShopBundle\Metrics\AbstractStatusProvider;
use KupShop\KupShopBundle\Metrics\StatusSample;

class FileSystemStatusProvider extends AbstractStatusProvider
{
    public function getData(): StatusSample|iterable
    {
        $data = md5((string) rand());
        $status = 1;

        if (file_put_contents('data/tmp/fstest', $data) === false) {
            $status = -1;
        }

        if (file_get_contents('data/tmp/fstest') != $data) {
            $status = -2;
        }

        if (unlink('data/tmp/fstest') === false) {
            $status = -3;
        }

        return new StatusSample('filesystem', $status);
    }
}
