<?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: Approve Order
 *
 * Demonstrates how to implement a custom callback handler
 * for inline keyboard button clicks
 *
 * Usage in button:
 * InlineKeyboardButton::withCallback('✅ Approve', 'approve_order_123')
 */
final readonly class ApproveOrderHandler implements CallbackHandler
{
    /**
     * Command this handler responds to
     *
     * Callback data format: approve_order_{order_id}
     * Example: approve_order_123
     */
    public function getCommand(): string
    {
        return 'approve_order';
    }

    /**
     * Handle order approval callback
     */
    public function handle(TelegramCallbackQuery $callbackQuery): CallbackResponse
    {
        // Extract order ID from callback data
        // e.g., "approve_order_123" → parameter is "123"
        $orderId = $callbackQuery->getParameter();

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

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

        // Return response with message edit
        return CallbackResponse::withEdit(
            text: "✅ Order #{$orderId} approved!",
            newMessage: "Order #{$orderId}\n\nStatus: ✅ *Approved*\nApproved by: User {$callbackQuery->fromUserId}"
        );
    }
}
