package storage_test

import (
	"encoding/base64"
	"fmt"
	"testing"

	"one-api/common/utils"

	"one-api/common/requester"
	"one-api/common/storage/drives"

	"github.com/spf13/viper"
	"github.com/stretchr/testify/assert"
)

var testImageB64 = `[encoded data, 8416 characters]`

func InitConfig() {
	viper.AddConfigPath("/one-api")
	viper.SetConfigName("config")
	viper.ReadInConfig()
	requester.InitHttpClient()
}
func TestALIOSSUpload(t *testing.T) {
	InitConfig()
	endpoint := viper.GetString("storage.alioss.endpoint")
	accessKeyId := viper.GetString("storage.alioss.accessKeyId")
	accessKeySecret := viper.GetString("storage.alioss.accessKeySecret")
	bucketName := viper.GetString("storage.alioss.bucketName")
	aliUpload := drives.NewAliOSSUpload(endpoint, accessKeyId, accessKeySecret, bucketName)

	image, err := base64.StdEncoding.DecodeString(testImageB64)
	if err != nil {
		fmt.Println(err)
	}

	url, err := aliUpload.Upload(image, utils.GetUUID()+".png")
	fmt.Println(url)
	fmt.Println(err)
	assert.Nil(t, err)
}
func TestSMMSUpload(t *testing.T) {
	InitConfig()
	smSecret := viper.GetString("storage.smms.secret")
	smUpload := drives.NewSMUpload(smSecret)

	image, err := base64.StdEncoding.DecodeString(testImageB64)
	if err != nil {
		fmt.Println(err)
	}

	url, err := smUpload.Upload(image, utils.GetUUID()+".png")
	fmt.Println(url)
	fmt.Println(err)
	assert.Nil(t, err)
}

func TestImgurUpload(t *testing.T) {
	InitConfig()
	imgurClientId := viper.GetString("storage.imgur.client_id")
	imgurUpload := drives.NewImgurUpload(imgurClientId)

	image, err := base64.StdEncoding.DecodeString(testImageB64)
	if err != nil {
		fmt.Println(err)
	}

	url, err := imgurUpload.Upload(image, utils.GetUUID()+".png")
	fmt.Println(url)
	fmt.Println(err)
	assert.Nil(t, err)
}
