package test

import (
	"context"
	"fmt"
	m "gitea.pena/PenaSide/common/mongo"
	"gitea.pena/PenaSide/heruvym/internal/repository/mongo"
	"gitea.pena/PenaSide/hlog"
	"github.com/stretchr/testify/assert"
	"go.uber.org/zap"
	"strconv"
	"testing"
	"time"
)

func TestGetMessagesPage(t *testing.T) {
	ctx := context.TODO()
	mdb, err := m.Connect(ctx, &m.ConnectDeps{
		Configuration: &m.Configuration{
			URL:          "mongodb://test:test@localhost:27020/",
			DatabaseName: "test",
		},
		Timeout: 10 * time.Second,
	})
	assert.NoError(t, err)
	mDal, err := mongo.New(ctx, mongo.DepsDAL{
		MongoDatabase: mdb,
		HLogger:       hlog.New(zap.NewExample()),
	})
	assert.NoError(t, err)

	for i := 1; i <= 10; i++ {
		iStr := strconv.Itoa(i)
		flag := false
		if i%2 == 0 {
			flag = true
		}
		_, err = mDal.PutMessage(ctx, iStr, iStr, iStr, iStr, []string{}, flag)
		assert.NoError(t, err)
	}

	result, err := mDal.GetMessagesPage(ctx, "", "2", "", 10, 0)
	assert.NoError(t, err)
	fmt.Println(result)
}
