package integration

import (
	"context"
	"github.com/pioz/faker"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/repository"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
	"strconv"
	"time"
)

//func TestLogostat(t *testing.T) {
//	logger, err := zap.NewProduction(zap.AddStacktrace(zap.DPanicLevel))
//	if err != nil {
//		log.Fatalf("failed to init zap logger: %v", err)
//	}
//	ctx := context.Background()
//	mongoDB, err := mongo.Connect(ctx, &mongo.ConnectDeps{
//		Configuration: &mongo.Configuration{
//			Host:         "localhost",
//			Port:         "27020",
//			User:         "test",
//			Password:     "test",
//			Auth:         "admin",
//			DatabaseName: "admin",
//		},
//		Timeout: 10 * time.Second,
//	})
//
//	repoAc := repository.NewAccountRepository2(logger, mongoDB.Collection("accounts"))
//	repoHi := repository.NewHistoryRepository2(logger, mongoDB.Collection("histories"))
//	InsertToDB(ctx, repoAc, repoHi)
//
//	api := http2.NewAPI2(logger, mongoDB, nil, nil, nil, nil)
//
//	app := fiber.New()
//	req := httptest.NewRequest(http.MethodGet, "/", nil)
//	req.Header.Set("Content-Type", "application/json")
//
//	requestBody := struct {
//		From  int
//		Limit int
//		Page  int
//		To    int
//	}{
//		From:  1713087258,
//		Limit: 10,
//		Page:  1,
//		To:    1713260058,
//	}
//
//	req = req.WithContext(context.WithValue(req.Context(), "requestBody", requestBody))
//	resp := httptest.NewRecorder()
//
//}

func InsertToDB(ctx context.Context, acc repository.AccountRepository, history repository.HistoryRepository) {
	partner1 := "partner1"
	partner2 := "partner2"
	qid1 := "qid1"
	qid2 := "qid2"
	acc.Insert(ctx, &models.Account{
		ID:        "1",
		UserID:    partner1,
		CreatedAt: time.Now(),
	})
	acc.Insert(ctx, &models.Account{
		ID:        "2",
		UserID:    partner2,
		CreatedAt: time.Now(),
	})

	for i := 1; i < 101; i++ {
		var partnerID string
		var qid string
		if i%2 == 0 {
			partnerID = partner2
			qid = qid2
		} else {
			partnerID = partner1
			qid = qid1
		}

		acc.Insert(ctx, &models.Account{
			ID:        "IDUSER" + strconv.Itoa(i),
			UserID:    strconv.Itoa(i),
			CreatedAt: time.Now(),
			From:      qid,
			Partner:   partnerID,
		})

		history.Insert(ctx, &models.History{
			ID:     "IDHISTORY" + strconv.Itoa(i),
			UserID: strconv.Itoa(i),
			RawDetails: models.RawDetails{
				Price: int64(faker.Uint64()),
			},
		})

	}

}
