<?php

/**
 * LolaCore - PlaybookDocumentTooLongException
 *
 * Thrown when extracted upload text exceeds the distiller input limit.
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Playbooks\Exceptions;

class PlaybookDocumentTooLongException extends \InvalidArgumentException
{
    public function __construct(
        private readonly int $charCount,
        private readonly int $maxChars
    ) {
        parent::__construct(
            sprintf(
                'Your document has %s characters of extracted text. The maximum is %s.',
                number_format($charCount),
                number_format($maxChars)
            )
        );
    }

    public function getCharCount(): int
    {
        return $this->charCount;
    }

    public function getMaxChars(): int
    {
        return $this->maxChars;
    }

    /**
     * @return array{code:string,message:string,char_count:int,max_chars:int}
     */
    public function toErrorPayload(): array
    {
        return [
            'code'       => 'document_too_long',
            'message'    => $this->getMessage(),
            'char_count' => $this->charCount,
            'max_chars'  => $this->maxChars,
        ];
    }
}
