package cache_test

import (
	"testing"

	"github.com/fiskerinc/cloud-services/pkg/cache"
	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/db"
	"github.com/fiskerinc/cloud-services/pkg/db/queries"
	"github.com/fiskerinc/cloud-services/pkg/db/queries/mocks"
	"github.com/fiskerinc/cloud-services/pkg/redis"
)

func TestRetrieveFileEncryptionParams(t *testing.T) {
	key := "b7f74938c9402dc2"
	c := NewMockRedisConn()
	q := mocks.MockFileKeys{
		GetResponse: &common.FileKey{},
	}

	_, err := cache.RetrieveFileEncryptionParams(c, &q, []string{key})
	if err != nil {
		t.Error(err)
	}
}

func BenchmarkRetrieveFileEncryptionParams(b *testing.B) {
	c := redis.NewClient()
	q := queries.FileKeys{}

	for n := 0; n < b.N; n++ {
		_, err := cache.RetrieveFileEncryptionParams(c, &q, []string{"b7f74938c9402dc2"})
		if err != nil {
			b.Error(err)
		}
	}
}

func NewMockRedisConn() *MockRedisConn {
	mock := &MockRedisConn{}
	mock.SetConn(redis.GetMockPool().Get())
	return mock
}

type MockRedisConn struct {
	redis.Connection
}

func (m *MockRedisConn) GetCache(id string, dest interface{}, expire int) error {
	return nil
}

func (m *MockRedisConn) SetCache(id string, data interface{}, expire int) error {
	return nil
}

func (m *MockRedisConn) GetValuesMulti(ids []string, data interface{}) error {
	return nil
}

func (m *MockRedisConn) SetMulti(ids []string, data []interface{}) error {
	return nil
}
func TestRetrieveFileEncryptionParamsIntegration(t *testing.T) {
	t.Skip()
	c := redis.NewClient()
	q := queries.FileKeys{}
	q.GetClient().GetConn().AddQueryHook(db.SQLLogger{})

	_, err := cache.RetrieveFileEncryptionParams(c, &q, []string{"bd2c7a6cc94042cb", "83165a80c940e8b3"})
	if err != nil {
		t.Error(err)
	}
}
