package tests

import (
	"context"
	"crypto/tls"
	"fmt"
	"gitea.pena/SQuiz/common/model"
	"gitea.pena/SQuiz/worker/internal/clients/gigachat"
	"gitea.pena/SQuiz/worker/internal/senders"
	"github.com/go-redis/redis/v8"
	"github.com/go-resty/resty/v2"
	"go.uber.org/zap"
	"testing"
	"time"
)

func TestGigachat(t *testing.T) {
	ctx := context.Background()
	logger, _ := zap.NewDevelopment()

	redisClient := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "admin",
		DB:       2,
	})

	tgSender, err := senders.NewTgSender("6712573453:AAFqTOsgwe_j48ZQ1GzWKQDT5Nwr-SAWjz8")
	if err != nil {
		panic(err)
	}

	gigaChatClient, err := gigachat.NewGigaChatClient(ctx, gigachat.Deps{
		Logger:      logger,
		Client:      resty.New().SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}),
		BaseURL:     "https://gigachat.devices.sberbank.ru/api/v1",
		AuthKey:     "Y2MzZWUxZDMtZGE5MC00ZTFjLWI5YzItM2ViMTZmMDM0YTkwOmY1NTlkOGM3LWUyNmQtNGUwMC1hODE0LTJlYjQ5NDA5ODdjMQ==",
		RedisClient: redisClient,

		TgSender: tgSender,
		TgChatID: -1002217604546,
	})
	if err != nil {
		panic(err)
	}

	go gigaChatClient.TokenResearch(ctx)
	go gigaChatClient.MonitorTokenBalance(ctx)

	result, err := gigaChatClient.SendMsg(ctx, model.GigaChatAudience{
		Sex: 1,
		Age: "17-23",
	}, model.Question{
		Title:       "О личной жизни",
		Description: "Как много у вас котят?",
	})
	if err != nil {
		panic(err)
	}

	fmt.Println(result)

	time.Sleep(10 * time.Minute)
}
