<?php declare(strict_types=1);

require_once __DIR__ . '/../../src/data/QrbProfileConfiguration.php';

use PHPUnit\Framework\TestCase;

final class QrbProfileConfigurationTest extends TestCase
{
    private $qrbCfg;
    
    protected function setUp(): void
    {
        $this->qrbCfg = new QrbProfileConfiguration();
    }

    public function testDefaultConfigurationAndToString() : void
    {
        $this->assertEquals(QrbProfileConfiguration::CHF, $this->qrbCfg->getCurrency());
        $this->assertEquals(QrbProfileConfiguration::NO_AMOUNT, $this->qrbCfg->getPrintAmount());
        $this->assertEquals(0.0, $this->qrbCfg->getAmount());
        $this->assertFalse($this->qrbCfg->getAddDebtor());
        $this->assertFalse($this->qrbCfg->getAddRefToAddInfo());
        $this->assertTrue($this->qrbCfg->getCreatePdf());
        $this->assertTrue($this->qrbCfg->getPrintPaymentSlip());
        $this->assertTrue($this->qrbCfg->getSendMail());
        $this->assertEquals(1000000, $this->qrbCfg->getSleepAfterSend());
        $this->assertEquals("", $this->qrbCfg->getPresetMail());
        $this->assertEquals("en", $this->qrbCfg->getDefaultLanguage());
        $this->assertFalse($this->qrbCfg->getMultiLanguage());
        $this->assertEquals(array(), $this->qrbCfg->getAdditionalLanguages());
        
        echo $this->qrbCfg . "\n"; 
    }    
    
    public function testSetCurrency() : void
    {
        // save
        $save = $this->qrbCfg->getCurrency();
        $this->assertEquals(QrbProfileConfiguration::CHF, $save);
        
        $this->qrbCfg->setCurrency(QrbProfileConfiguration::EUR);
        $this->assertEquals(QrbProfileConfiguration::EUR, $this->qrbCfg->getCurrency());

        // restore
        $this->qrbCfg->setCurrency($save);
        $this->assertEquals(QrbProfileConfiguration::CHF, $this->qrbCfg->getCurrency());
    }
    
    public function testSetPrintAmount() : void
    {
        // save
        $save = $this->qrbCfg->getPrintAmount();
        $this->assertEquals(QrbProfileConfiguration::NO_AMOUNT, $save);
        
        $this->qrbCfg->setPrintAmount(QrbProfileConfiguration::GLOBAL_AMOUNT);
        $this->assertEquals(QrbProfileConfiguration::GLOBAL_AMOUNT, $this->qrbCfg->getPrintAmount());

        $this->qrbCfg->setPrintAmount(QrbProfileConfiguration::INDIVIDUAL_AMOUNT);
        $this->assertEquals(QrbProfileConfiguration::INDIVIDUAL_AMOUNT, $this->qrbCfg->getPrintAmount());

        // restore
        $this->qrbCfg->setPrintAmount($save);
        $this->assertEquals(QrbProfileConfiguration::NO_AMOUNT, $this->qrbCfg->getPrintAmount());
    }
    
    public function testSetAmount() : void
    {
        // save
        $save = $this->qrbCfg->getAmount();
        $this->assertEquals(0.0, $save);
        
        $this->qrbCfg->setAmount(127.65);
        $this->assertEquals(127.65, $this->qrbCfg->getAmount());

        // restore
        $this->qrbCfg->setAmount($save);
        $this->assertEquals(0.0, $this->qrbCfg->getAmount());
    }
    
    public function testSetAddDebtor() : void
    {
        // save
        $save = $this->qrbCfg->getAddDebtor();
        $this->assertFalse($save);
        
        $this->qrbCfg->setAddDebtor(true);
        $this->assertTrue($this->qrbCfg->getAddDebtor());

        // restore
        $this->qrbCfg->setAddDebtor($save);
        $this->assertFalse($this->qrbCfg->getAddDebtor());
    }
    
    public function testSetAddRefToAddInfo() : void
    {
        // save
        $save = $this->qrbCfg->getAddRefToAddInfo();
        $this->assertFalse($save);
        
        $this->qrbCfg->setAddRefToAddInfo(true);
        $this->assertTrue($this->qrbCfg->getAddRefToAddInfo());

        // restore
        $this->qrbCfg->setAddRefToAddInfo($save);
        $this->assertFalse($this->qrbCfg->getAddRefToAddInfo());
    }
    
    public function testSetCreatePdf() : void
    {
        // save
        $save = $this->qrbCfg->getCreatePdf();
        $this->assertTrue($save);
        
        $this->qrbCfg->setCreatePdf(false);
        $this->assertFalse($this->qrbCfg->getCreatePdf());

        // restore
        $this->qrbCfg->setCreatePdf($save);
        $this->assertTrue($this->qrbCfg->getCreatePdf());
    }
    
    public function testSetPrintPaymentSlip() : void
    {
        // save
        $save = $this->qrbCfg->getPrintPaymentSlip();
        $this->assertTrue($save);
        
        $this->qrbCfg->setPrintPaymentSlip(false);
        $this->assertFalse($this->qrbCfg->getPrintPaymentSlip());

        // restore
        $this->qrbCfg->setPrintPaymentSlip($save);
        $this->assertTrue($this->qrbCfg->getPrintPaymentSlip());
    }
    
    public function testSetSendMail() : void
    {
        // save
        $save = $this->qrbCfg->getSendMail();
        $this->assertTrue($save);
        
        $this->qrbCfg->setSendMail(false);
        $this->assertFalse($this->qrbCfg->getSendMail());

        // restore
        $this->qrbCfg->setSendMail($save);
        $this->assertTrue($this->qrbCfg->getSendMail());
    }
    
    public function testSetSleepAfterSend() : void
    {
        // save
        $save = $this->qrbCfg->getSleepAfterSend();
        $this->assertEquals(1000000, $save);
        
        $this->qrbCfg->setSleepAfterSend(200000);
        $this->assertEquals(200000, $this->qrbCfg->getSleepAfterSend());

        // restore
        $this->qrbCfg->setSleepAfterSend($save);
        $this->assertEquals(1000000, $this->qrbCfg->getSleepAfterSend());
    }
    
    public function testSetPresetMail() : void
    {
        // save
        $save = $this->qrbCfg->getPresetMail();
        $this->assertEquals("", $save);
        
        $this->qrbCfg->setPresetMail("muster@example.com");
        $this->assertEquals("muster@example.com", $this->qrbCfg->getPresetMail());

        // restore
        $this->qrbCfg->setPresetMail($save);
        $this->assertEquals("", $this->qrbCfg->getPresetMail());
    }
    
    public function testSetDefaultLanguage() : void
    {
        // save
        $save = $this->qrbCfg->getDefaultLanguage();
        $this->assertEquals("en", $save);
        
        $this->qrbCfg->setDefaultLanguage("de");
        $this->assertEquals("de", $this->qrbCfg->getDefaultLanguage());

        // restore
        $this->qrbCfg->setDefaultLanguage($save);
        $this->assertEquals("en", $this->qrbCfg->getDefaultLanguage());
    }
    
    public function testSetAdditionalLanguages() : void
    {
        // save
        $save = $this->qrbCfg->getAdditionalLanguages();
        $this->assertEquals(array(), $save);
        
        $this->qrbCfg->setAdditionalLanguages(["it","fr"]);
        $this->assertEquals(["it","fr"], $this->qrbCfg->getAdditionalLanguages());

        // restore
        $this->qrbCfg->setAdditionalLanguages($save);
        $this->assertEquals(array(), $this->qrbCfg->getAdditionalLanguages());
    }
}

?>
