<?php

declare(strict_types=1);

namespace App\Scenario;

use App\Util\ParsedCommand;
use Pkirillw\MaxBotApi\Builder\Keyboard;
use Pkirillw\MaxBotApi\Builder\Message as MessageBuilder;
use Pkirillw\MaxBotApi\Scheme\Enum\Format;
use Pkirillw\MaxBotApi\Scheme\Enum\Intent;
use Pkirillw\MaxBotApi\Scheme\Update\MessageCreatedUpdate;

final class HelpScenario extends AbstractScenario
{
    public function handle(MessageCreatedUpdate $update, ParsedCommand $command): void
    {
        $keyboard = new Keyboard();
        $keyboard->addRow()
            ->addCallback('Клавиатуры', 'demo_keyboard', Intent::Positive)
            ->addCallback('Загрузки', 'demo_uploads');
        $keyboard->addRow()->addLink('Документация MAX', 'https://dev.max.ru');

        $text = <<<'MD'
            *max-bot-test* — тестовый бот для [`max-bot-api-php`]

            Доступные команды:

            *Bot*
            /bot — getBot()
            /bot_patch <name> — patchBot()

            *Chats*
            /chats [count] — getChats()
            /chat <id> — getChat() + getChatMembership()
            /members <id> — getChatMembers() + getChatAdmins()
            /action <chatId> <typing_on|typing_off|mark_seen|sending_photo|sending_video|sending_audio> — sendAction()
            /pin <chatId> <messageId> — pinMessage()
            /edit_chat <chatId> <title> — editChat()
            /add_member <chatId> <userId> — addMember()
            /remove_member <chatId> <userId> — removeMember()
            /leave <chatId> — leaveChat()

            *Messages*
            /send_text <text> — send() plain
            /send_markdown <text> — Format::Markdown
            /send_html <text> — Format::Html
            /reply <messageId> <text> — setReply()
            /forward <messageId> — setForward()
            /edit <messageId> <text> — editMessage()
            /delete <messageId> — deleteMessage()
            /messages <chatId> [count] — getMessages()
            /message <messageId> — getMessage()
            /markup <userId> — addMarkUp() (mention)
            /notify <text> — setNotify(false) (silent)
            /disable_preview <url> — setDisableLinkPreview(true)
            /keyboard — inline keyboard со всеми 8 типами кнопок

            *Uploads*
            /upload_photo_file [path] — uploadPhotoFromFile()
            /upload_photo_url <url> — uploadPhotoFromUrl()
            /upload_photo_bytes — uploadPhotoFromBytes()
            /upload_photo_base64 — uploadPhotoFromBase64()
            /upload_audio [path] — uploadMediaFromFile(Audio)
            /upload_video [path] — uploadMediaFromFile(Video)
            /upload_file [path] — uploadMediaFromFile(File)
            /upload_url <audio|video|file> <url> — uploadMediaFromUrl()

            *Attachments*
            /attach_location <lat> <lng> — addLocation()
            /attach_contact <name> <userId> — addContact()
            /attach_sticker <code> — addSticker()

            *Phone (notify)*
            /phone_check <phone> — check()
            /phone_list <phone1,phone2> — listExist()

            *Subscriptions (CLI)*
            `make subscribe`, `make unsubscribe`, `bin/console subs:list`

            *Debug*
            /debug <on|off|raw|err> — переключение Debugs + Options::withDebug
            MD;

        $this->api->messages->send(
            MessageBuilder::new()
                ->setChat($update->getChatId())
                ->setText($text)
                ->setFormat(Format::Markdown)
                ->addKeyboard($keyboard),
        );
    }

    public function handleUnknown(MessageCreatedUpdate $update, ParsedCommand $command): void
    {
        $this->replyMarkdown(
            $update,
            sprintf('Не знаю команду `%s`. Набери `/help`.', $command->name),
        );
    }
}
