<?php

namespace Openguru\OpenCartFramework\Telegram\Commands;

use Openguru\OpenCartFramework\Config\Settings;
use Openguru\OpenCartFramework\Telegram\Enums\ChatAction;
use Openguru\OpenCartFramework\Telegram\TelegramBotStateManager;
use Openguru\OpenCartFramework\Telegram\TelegramService;

class StartCommand extends TelegramCommand
{
    private Settings $settings;

    public function __construct(TelegramService $telegram, TelegramBotStateManager $stateManager, Settings $settings)
    {
        parent::__construct($telegram, $stateManager);
        $this->settings = $settings;
    }

    public function handle(array $update): void
    {
        $chatId = $update['message']['chat']['id'];

        $message = $this->settings->get('texts.start_message', 'Welcome to Telecart - Telegram e-commerce solution.');
        $buttons = [
            'inline_keyboard' => [
                [
                    [
                        'text' => $this->settings->get('texts.start_button.text', 'Open Mini App'),
                        'url' => $this->telegram->getMiniAppUrl(),
                    ],
                ],
            ],
        ];

        $this->telegram->sendMessage($chatId, $message, $buttons);
    }
}
