<?php

declare(strict_types=1);

namespace App\Handler\Update;

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

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

    public function handle(UpdateInterface $update): void
    {
        if (!$update instanceof DialogClearedFromChatUpdate) {
            return;
        }
        $this->logger->info('dialog cleared', [
            'chat_id' => $update->chatId,
            'by_user_id' => $update->user->userId,
        ]);
        // Demonstrate Debugs::send(update) — pushes raw payload to the debug chat.
        if ($this->api->debugs->getChatId() !== null) {
            $this->api->debugs->send($update);
        }
    }
}
