<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\Entity;

use Ferienpass\CoreBundle\Entity\AgreementLetterSignature;
use Ferienpass\CoreBundle\Entity\Edition;
use Ferienpass\CoreBundle\Entity\User;
use PHPUnit\Framework\TestCase;

final class AgreementLetterSignatureTest extends TestCase
{
    public function testGetEditionReturnsEdition(): void
    {
        $user = new User();
        $edition = new Edition();
        $signature = new AgreementLetterSignature($user, $edition, 'abc123');

        self::assertSame($edition, $signature->getEdition());
    }

    public function testFromEditionCreatesSignatureWithHash(): void
    {
        $user = new User();
        $edition = new Edition();

        $rp = new \ReflectionProperty($edition, 'agreementLetterText');
        $rp->setValue($edition, 'Some legal text');

        $signature = AgreementLetterSignature::fromEdition($edition, $user);

        self::assertSame($edition, $signature->getEdition());
        self::assertSame($user, $signature->getUser());
    }

    public function testFromEditionHashIsSha256OfText(): void
    {
        $user = new User();
        $edition = new Edition();

        $rp = new \ReflectionProperty($edition, 'agreementLetterText');
        $rp->setValue($edition, 'My agreement text');

        $signature = AgreementLetterSignature::fromEdition($edition, $user);
        $expectedHash = hash('sha256', 'My agreement text');

        self::assertSame($expectedHash, $signature->getHash());
    }
}
