<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/process/QrbProtocol.php';

require_once __DIR__ . '/../../src/storage/QrbStorage.php';
require_once __DIR__ . '/../../src/storage/QrbStorageFactory.php';

use PHPUnit\Framework\TestCase;

final class QrbProtocolTest extends TestCase
{
    private QrbStorage $qrbStorage;

    protected function setUp() : void
    {
        $this->qrbStorage = new QrbFileStorage();
        $this->qrbStorage->initializeNewRun("ProtocolTest", false, false);
    }
    
    protected function tearDown() : void
    {
        $this->qrbStorage->deleteData();
    }

    public function testCreateEntryAndToString() : void
    {
        $qrbProtocol = new QrbProtocol($this->qrbStorage);
        $qrbProtocol->createEntry($this->createRecipient(1));
        $qrbProtocol->createEntry($this->createRecipient(2));
        print $qrbProtocol . "\n";
        $this->assertNotNull($qrbProtocol->write());
    }
    
    private function createRecipient(int $index) : QrbRecipient
    {
        $line = array();
        array_push($line, "en");
        $headerNames = array();
        $headerNames[QrbRecipient::HDR_LANGUAGE] = 0;
        $supportedLanguages = array();
        array_push($supportedLanguages, "en");
        return new QrbRecipient($index, $line, $headerNames, false, false, false, false, $supportedLanguages);
    }
    
    public function testWriteEmptyProtocol()
    {
        $qrbProtocol = new QrbProtocol($this->qrbStorage);
        $this->assertNull($qrbProtocol->write());
    }
    
    public function testWriteNonEmptyProtocol()
    {
        $qrbProtocol = new QrbProtocol($this->qrbStorage);
        $qrbProtocol->createEntry($this->createRecipient(1));
        $this->assertNotNull($qrbProtocol->write());
    }
}

?>
