<?php

declare(strict_types=1);

namespace App\Keyboard;

use Pkirillw\MaxBotApi\Builder\Keyboard;
use Pkirillw\MaxBotApi\Scheme\Enum\Intent;

/**
 * Pre-built keyboards that exercise every button type supported by the library.
 */
final class KeyboardFactory
{
    public function __construct(private readonly ?string $webAppUrl = null) {}

    /**
     * Full keyboard — one row per button type, plus a 3-button callback row with all Intents.
     * OpenApp button is only added when WEB_APP_URL points to a real, bot-registered web app.
     */
    public function full(): Keyboard
    {
        $kb = new Keyboard();

        $row = $kb->addRow();
        $row->addCallback('Callback: Positive', 'cb:positive', Intent::Positive)
            ->addCallback('Callback: Negative', 'cb:negative', Intent::Negative)
            ->addCallback('Callback: Default', 'cb:default', Intent::Default);

        $kb->addRow()->addLink('Link: dev.max.ru', 'https://dev.max.ru');
        $kb->addRow()->addMessage('Message: send this text');
        $kb->addRow()->addClipboard('Clipboard: copy token', 'TOKEN-12345');
        $kb->addRow()->addContact('Request contact');
        $geo = $kb->addRow();
        $geo->addGeolocation('Request geo')
            ->addGeolocation('Request geo (quick)', quick: true);
        if ($this->webAppUrl !== null && $this->webAppUrl !== '') {
            $kb->addRow()->addOpenApp('Open web app', $this->webAppUrl, 'demo-payload');
        }

        return $kb;
    }

    public function simpleCallback(): Keyboard
    {
        $kb = new Keyboard();
        $kb->addRow()
            ->addCallback('Yes', 'vote:yes', Intent::Positive)
            ->addCallback('No', 'vote:no', Intent::Negative);
        return $kb;
    }
}
