<?php

declare(strict_types=1);

namespace PhpWA\Crypto\Signal;

use InvalidArgumentException;

final class SignalSessionIndex
{
    public const BASE_OURS = 1;
    public const BASE_THEIRS = 2;

      private $baseKey;
      private $baseKeyType;
      private $remoteIdentityKey;
      private $closed;

    public function __construct(string $baseKey, int $baseKeyType, string $remoteIdentityKey, int $closed = -1)
    {
        SignalCurve::assertPublicKey($baseKey);
        SignalCurve::assertPublicKey($remoteIdentityKey);
        if (($baseKeyType !== self::BASE_OURS && $baseKeyType !== self::BASE_THEIRS) || $closed < -1) {
            throw new InvalidArgumentException('Signal session index is invalid.');
        }
        $this->baseKey = $baseKey;
        $this->baseKeyType = $baseKeyType;
        $this->remoteIdentityKey = $remoteIdentityKey;
        $this->closed = $closed;
    }

    public function baseKey(): string { return $this->baseKey; }
    public function baseKeyType(): int { return $this->baseKeyType; }
    public function remoteIdentityKey(): string { return $this->remoteIdentityKey; }
    public function closed(): int { return $this->closed; }
    public function close(): void { if ($this->closed === -1) { $this->closed = 0; } }
}
