package types

import (
	"gitlink.org.cn/cloudream/common/pkgs/types"
	"gitlink.org.cn/cloudream/common/utils/serder"
)

type StorageCredential interface {
	GetStorageCredentialType() string
}

var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageCredential](
	(*LocalCred)(nil),
	(*MashupCred)(nil),
	(*OBSCred)(nil),
	(*OSSCred)(nil),
	(*COSCred)(nil),
	(*EFileCred)(nil),
	(*S3Cred)(nil),
)), "type")

type LocalCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"Local"`
	Type              string `json:"type"`
	RootDir           string `json:"rootDir"`
}

type MashupCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"Mashup"`
	Store             StorageCredential `json:"store"`
	Feature           StorageCredential `json:"feature"`
}

type OSSCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"OSS"`
	Type              string `json:"type"`
	Region            string `json:"region"`
	AK                string `json:"accessKeyId"`
	SK                string `json:"secretAccessKey"`
	Endpoint          string `json:"endpoint"`
	Bucket            string `json:"bucket"`
}

type OBSCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"OBS"`
	Type              string `json:"type"`
	Region            string `json:"region"`
	AK                string `json:"accessKeyId"`
	SK                string `json:"secretAccessKey"`
	Endpoint          string `json:"endpoint"`
	Bucket            string `json:"bucket"`
	ProjectID         string `json:"projectID"`
}

type COSCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"COS"`
	Type              string `json:"type"`
	Region            string `json:"region"`
	AK                string `json:"accessKeyId"`
	SK                string `json:"secretAccessKey"`
	Endpoint          string `json:"endpoint"`
	Bucket            string `json:"bucket"`
}

type EFileCred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"EFile"`
	Type              string `json:"type"`
	TokenURL          string `json:"tokenURL"`
	APIURL            string `json:"apiURL"`
	TokenExpire       int    `json:"tokenExpire"` // 单位秒
	User              string `json:"user"`
	Password          string `json:"password"`
	OrgID             string `json:"orgID"`
	ClusterID         string `json:"clusterID"`
}

// 通用的S3协议的存储服务
type S3Cred struct {
	StorageCredential `json:"-"`
	serder.Metadata   `union:"S3"`
	Type              string `json:"type"`
	Region            string `json:"region"`
	AK                string `json:"accessKeyId"`
	SK                string `json:"secretAccessKey"`
	Endpoint          string `json:"endpoint"`
	Bucket            string `json:"bucket"`
}
