<?php

declare(strict_types=1);

namespace App\Handler\Update;

use App\Handler\AbstractUpdateHandler;
use Pkirillw\MaxBotApi\Api;
use Pkirillw\MaxBotApi\Scheme\Update\BotStopedFromChatUpdate;
use Pkirillw\MaxBotApi\Scheme\Update\UpdateInterface;
use Psr\Log\LoggerInterface;

final class BotStopedFromChatHandler extends AbstractUpdateHandler
{
    public function updateClass(): string { return \Pkirillw\MaxBotApi\Scheme\Update\BotStopedFromChatUpdate::class; }

    public function handle(UpdateInterface $update): void
    {
        if (!$update instanceof BotStopedFromChatUpdate) {
            return;
        }
        $this->logger->info('bot stopped (blocked) by user', [
            'chat_id' => $update->chatId,
            'user_id' => $update->user->userId,
        ]);
        if ($this->api->debugs->getChatId() !== null) {
            $this->api->debugs->sendText(sprintf('user %d stopped the bot', $update->user->userId));
        }
    }
}
