<?php

declare(strict_types=1);

namespace PhpWA\Media;

use InvalidArgumentException;

final class EncryptedMedia
{
    /** @var string */ private $path;
    /** @var string */ private $type;
    /** @var string */ private $mediaKey;
    /** @var string */ private $fileSha256;
    /** @var string */ private $fileEncSha256;
    /** @var int */ private $fileLength;
    /** @var int */ 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; }
}
