<?php

declare(strict_types=1);

namespace App\Handler\Update;

use App\Handler\AbstractUpdateHandler;
use Pkirillw\MaxBotApi\Api;
use Pkirillw\MaxBotApi\Builder\Message as MessageBuilder;
use Pkirillw\MaxBotApi\Scheme\Update\MessageRemovedUpdate;
use Pkirillw\MaxBotApi\Scheme\Update\UpdateInterface;
use Psr\Log\LoggerInterface;

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

    public function handle(UpdateInterface $update): void
    {
        if (!$update instanceof MessageRemovedUpdate) {
            return;
        }
        $this->logger->info('message removed', [
            'message_id' => $update->messageId,
            'chat_id' => $update->chatId,
            'user_id' => $update->userId,
        ]);
        // No chat context to reply into reliably here — leave a debug trail.
        if ($this->api->debugs->getChatId() !== null) {
            $this->api->debugs->sendText(sprintf('removed: mid=%s user=%d', $update->messageId, $update->userId));
        }
    }
}
