package bot

import (
	"context"
	"strings"
	"testing"

	"github.com/go-telegram/bot/models"
)

func TestHandleSupportRepliesPrivateOnly(t *testing.T) {
	t.Run("english by default", func(t *testing.T) {
		api := &fakeBotAPI{}
		b := newTestBot(t, api)
		b.handleSupport(context.Background(), b.api, &models.Update{Message: &models.Message{
			Chat: models.Chat{ID: 42, Type: models.ChatTypePrivate}, Text: "/support",
		}})
		if api.chatID != "42" {
			t.Errorf("chat_id = %q, want 42", api.chatID)
		}
		// No reported language -> English support reply.
		if !strings.Contains(api.text, "support is available") {
			t.Errorf("text = %q, want the English support reply", api.text)
		}
		// A plain info message carries no launch button.
		if api.replyMarkup != "" {
			t.Errorf("reply_markup = %q, want none", api.replyMarkup)
		}
	})
	t.Run("russian for a ru sender", func(t *testing.T) {
		api := &fakeBotAPI{}
		b := newTestBot(t, api)
		b.handleSupport(context.Background(), b.api, &models.Update{Message: &models.Message{
			Chat: models.Chat{ID: 42, Type: models.ChatTypePrivate}, Text: "/support",
			From: &models.User{ID: 7, LanguageCode: "ru"},
		}})
		if !strings.Contains(api.text, "Поддержка «Эрудита»") {
			t.Errorf("text = %q, want the Russian support reply", api.text)
		}
	})
	t.Run("group ignored", func(t *testing.T) {
		api := &fakeBotAPI{}
		b := newTestBot(t, api)
		b.handleSupport(context.Background(), b.api, &models.Update{Message: &models.Message{
			Chat: models.Chat{ID: -100, Type: models.ChatTypeSupergroup}, Text: "/support",
		}})
		if api.chatID != "" {
			t.Errorf("group /support got a reply (chat=%q); the bot never chats in the group", api.chatID)
		}
	})
}
