<?php

declare(strict_types=1);

namespace PhpWA\Media;

use InvalidArgumentException;

final class EncryptedMedia
{
      private $path;
      private $type;
      private $mediaKey;
      private $fileSha256;
      private $fileEncSha256;
      private $fileLength;
      private $encryptedLength;

    public function __construct(string $path, string $type, string $mediaKey, string $fileSha256, string $fileEncSha256, int $fileLength, int $encryptedLength)
    {
        MediaType::hkdfInfo($type);
        if ($path === '' || strlen($mediaKey) !== 32 || strlen($fileSha256) !== 32 || strlen($fileEncSha256) !== 32
            || $fileLength < 0 || $encryptedLength < 26 || (($encryptedLength - 10) % 16) !== 0) {
            throw new InvalidArgumentException('Encrypted media metadata is invalid.');
        }
        $this->path = $path; $this->type = $type; $this->mediaKey = $mediaKey;
        $this->fileSha256 = $fileSha256; $this->fileEncSha256 = $fileEncSha256;
        $this->fileLength = $fileLength; $this->encryptedLength = $encryptedLength;
    }

    public function path(): string { return $this->path; }
    public function type(): string { return $this->type; }
    public function mediaKey(): string { return $this->mediaKey; }
    public function fileSha256(): string { return $this->fileSha256; }
    public function fileEncSha256(): string { return $this->fileEncSha256; }
    public function fileLength(): int { return $this->fileLength; }
    public function encryptedLength(): int { return $this->encryptedLength; }
}
