<?php
namespace Bot\Commands\UserCommands;

use Bot\Database;
use Bot\Localization;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Request;
use PDO;

class HelpCommand extends UserCommand
{
    protected $name = 'help';
    protected $description = 'Show available user commands';
    protected $usage = '/help';
    protected $version = '1.0.0';

    private PDO $pdo;

    public function __construct($telegram, $update)
    {
        parent::__construct($telegram, $update);
        $this->pdo = Database::connection();
    }

    public function execute(): ServerResponse
    {
        $message = $this->getMessage();
        $chatId = $message->getChat()->getId();
        $telegramId = $message->getFrom()->getId();
        $stmt = $this->pdo->prepare('SELECT language FROM users WHERE telegram_id = ?');
        $stmt->execute([$telegramId]);
        $lang = $stmt->fetchColumn() ?: 'en';

        $commands = [
            '/start'                  => 'Register or refresh the main menu',
            '/help'                   => 'Show every available user command',
            '/points'                 => 'View referral tier, points, and rewards',
            '/convertpoints <amount>' => 'Convert referral points to USDT balance',
            '/withdraw'               => 'Request a crypto withdrawal (KYC required)',
            '/virtualcard'            => 'Check the virtual card rollout status',
        ];
        $lines = ["Available commands:"];
        foreach ($commands as $command => $description) {
            $lines[] = sprintf('%s — %s', $command, $description);
        }
        $lines[] = '';
        $lines[] = 'Tip: use the on-screen menu to Buy/Sell, open your Wallet, or reach Help & Support.';
        $text = implode("\n", $lines);

        return Request::sendMessage([
            'chat_id' => $chatId,
            'text'    => $text,
        ]);
    }
}
