package s3storage

import (
	"bytes"
	"context"
	"io"

	awsconfig "github.com/aws/aws-sdk-go-v2/config"
	"github.com/tidbcloud/observability/pkg/common/constants"
)

type Client interface {
	Get(ctx context.Context, bucketName string, objectName string) (*io.ReadCloser, error)
	Put(ctx context.Context, bucketName string, objectName string, reader *bytes.Reader) error
	GetLarge(ctx context.Context, bucketName string, objectName string) (*io.ReadCloser, error)
	PutLarge(ctx context.Context, bucketName string, objectName string, reader *bytes.Reader) error
}

func PrepareS3Client(ctx context.Context, vendor string, region string, project string) Client {
	var cli Client = nil
	if vendor == string(constants.AWS) {
		//we should  init aws config and client before start Observe
		cfg, err := awsconfig.LoadDefaultConfig(ctx)
		if err != nil {
			panic(err) // Consider returning an error instead of panicking
		}
		cfg.Region = region
		cli = NewS3(cfg)
	} else if vendor == string(constants.GCP) {
		cli = NewCloudStorage(project, region)
	} else if vendor == string(constants.AliCloud) {
		cli = NewAliyunOSSClient(region)
	}
	return cli
}
