<?php

declare(strict_types=1);

namespace App\Framework\Notification\Channels\Telegram\Webhook\Examples;

use App\Framework\Notification\Channels\Telegram\Webhook\{CallbackHandler, CallbackResponse, TelegramCallbackQuery};

/**
 * Example Callback Handler: Reject Order
 *
 * Demonstrates callback handler with alert popup
 *
 * Usage in button:
 * InlineKeyboardButton::withCallback('❌ Reject', 'reject_order_123')
 */
final readonly class RejectOrderHandler implements CallbackHandler
{
    public function getCommand(): string
    {
        return 'reject_order';
    }

    public function handle(TelegramCallbackQuery $callbackQuery): CallbackResponse
    {
        $orderId = $callbackQuery->getParameter();

        if ($orderId === null) {
            return CallbackResponse::alert('Invalid order ID');
        }

        // TODO: Implement actual order rejection logic
        // $this->orderService->reject($orderId);

        // Return alert popup with message edit
        return CallbackResponse::withEdit(
            text: "Order #{$orderId} has been rejected",
            newMessage: "Order #{$orderId}\n\nStatus: ❌ *Rejected*\nRejected by: User {$callbackQuery->fromUserId}"
        );
    }
}
