<?php

declare(strict_types=1);

namespace App\Scenario;

use App\Keyboard\KeyboardFactory;
use App\Util\ParsedCommand;
use Pkirillw\MaxBotApi\Api;
use Pkirillw\MaxBotApi\Builder\Message as MessageBuilder;
use Pkirillw\MaxBotApi\Scheme\Enum\Format;
use Pkirillw\MaxBotApi\Scheme\Update\MessageCreatedUpdate;
use Psr\Log\LoggerInterface;

abstract class AbstractScenario implements ScenarioInterface
{
    public function __construct(
        protected Api $api,
        protected LoggerInterface $logger,
        protected KeyboardFactory $keyboards,
    ) {}

    protected function reply(MessageCreatedUpdate $update, string $text, ?Format $format = null): void
    {
        $builder = MessageBuilder::new()
            ->setChat($update->getChatId())
            ->setText($text);
        if ($format !== null) {
            $builder->setFormat($format);
        }
        $this->api->messages->send($builder);
    }

    protected function replyMarkdown(MessageCreatedUpdate $update, string $text): void
    {
        $this->reply($update, $text, Format::Markdown);
    }

    protected function err(string $message, ParsedCommand $command): void
    {
        $this->logger->error($message, ['command' => $command->name, 'args' => $command->args]);
    }
}
