<?php

/**
 * LolaCore - PlaybookParseError
 *
 * Thrown when a playbook markdown file cannot be parsed (missing
 * frontmatter, unreadable file, or YamlParser failure).
 *
 * @package LolaCore
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Playbooks\Exceptions;

class PlaybookParseError extends \RuntimeException
{
    private int $lineNumber;
    private string $token;
    private string $filePath;

    public function __construct(string $message, int $lineNumber, string $token, string $filePath = '')
    {
        parent::__construct($message);
        $this->lineNumber = $lineNumber;
        $this->token      = $token;
        $this->filePath   = $filePath;
    }

    public function getLineNumber(): int
    {
        return $this->lineNumber;
    }

    public function getToken(): string
    {
        return $this->token;
    }

    public function getFilePath(): string
    {
        return $this->filePath;
    }

    public function getUserMessage(): string
    {
        $path = $this->filePath !== '' ? $this->filePath : '(inline)';
        return sprintf(
            "Playbook parse error in '%s' at line %d: unsupported construct '%s'.",
            $path,
            $this->lineNumber,
            $this->token
        );
    }
}
