<?php

declare(strict_types=1);

namespace PhpWA\Client;

use InvalidArgumentException;

final class EncryptedMessagePart
{
    /** @var string */ private $type;
    /** @var int */ private $version;
    /** @var string */ private $ciphertext;
    /** @var int */ private $retryCount;

    public function __construct(string $type, int $version, string $ciphertext, int $retryCount = 0)
    {
        if (!in_array($type, ['pkmsg', 'msg', 'skmsg'], true) || ($version !== 2 && $version !== 3)
            || $ciphertext === '' || strlen($ciphertext) > 4194304 || $retryCount < 0 || $retryCount > 10) {
            throw new InvalidArgumentException('Encrypted message part is invalid.');
        }
        $this->type = $type;
        $this->version = $version;
        $this->ciphertext = $ciphertext;
        $this->retryCount = $retryCount;
    }

    public function type(): string { return $this->type; }
    public function version(): int { return $this->version; }
    public function ciphertext(): string { return $this->ciphertext; }
    public function retryCount(): int { return $this->retryCount; }
}
