package upload

import (
	"fmt"
	"mime/multipart"
	"sundynix-go/global"
)

// Oss 对象存储接口
type Oss interface {
	UploadFile(file *multipart.FileHeader) (string, string, error)
	DeleteFile(key string) error
}

// OssInstance 实例化oos方法
func OssInstance() Oss {
	switch global.Config.System.OssType {
	case "local":
		fmt.Println("local")
	case "tencent-cos":
		return &TencentCOS{}
	case "minio":
		minioClient, err := GetMinio(global.Config.Minio.Endpoint, global.Config.Minio.AccessKeyId, global.Config.Minio.AccessKeySecret, global.Config.Minio.BucketName, global.Config.Minio.UseSSL)
		if err != nil {
			global.Logger.Warn("minio初始化失败,请检查minio可用性或安全配置:" + err.Error())
			panic("minio初始化失败,请检查minio可用性或安全配置")
		}
		return minioClient
	}
	return nil
}
