<?php

declare(strict_types=1);

namespace PhpWA\Exception;

use InvalidArgumentException;

final class MediaDownloadPendingException extends PhpWAException
{
    /** @var int */ private $downloadedBytes;
    /** @var int */ private $totalBytes;

    public function __construct(int $downloadedBytes, int $totalBytes, ?\Throwable $previous = null)
    {
        if ($totalBytes < 1 || $downloadedBytes < 0 || $downloadedBytes > $totalBytes) {
            throw new InvalidArgumentException('Pending media download progress is invalid.');
        }
        parent::__construct('Media download is incomplete and can be resumed by repeating the same operation.', 0, $previous);
        $this->downloadedBytes = $downloadedBytes;
        $this->totalBytes = $totalBytes;
    }

    public function downloadedBytes(): int { return $this->downloadedBytes; }
    public function totalBytes(): int { return $this->totalBytes; }
}
