package svc

import (
	"backend/internal/config"
	fileStorageConfig "backend/pkg/fileStorage/config"
	fileStorageUC "backend/pkg/fileStorage/domain/usecase"
	fileStorageRepo "backend/pkg/fileStorage/repository"
	fileStorageUseCase "backend/pkg/fileStorage/usecase"
	errs "backend/pkg/library/errors"
)

func MustS3Storage(c *config.Config, logger errs.Logger) fileStorageUC.FileStorageUseCase {
	// 初始化 FileStorage 配置
	fileStorageConf := &fileStorageConfig.Config{
		AmazonS3Settings: struct {
			Region           string
			Bucket           string
			CloudFrontDomain string
			CloudFrontURI    string
			BucketURI        string
			AccessKey        string
			SecretKey        string
			CloudFrontID     string
		}{
			Region:           c.AmazonS3Settings.Region,
			Bucket:           c.AmazonS3Settings.Bucket,
			CloudFrontDomain: c.AmazonS3Settings.CloudFrontDomain,
			CloudFrontURI:    c.AmazonS3Settings.CloudFrontURI,
			BucketURI:        c.AmazonS3Settings.BucketURI,
			AccessKey:        c.AmazonS3Settings.AccessKey,
			SecretKey:        c.AmazonS3Settings.SecretKey,
			CloudFrontID:     c.AmazonS3Settings.CloudFrontID,
		},
	}

	// 初始化 FileStorage Repository 和 UseCase
	fileStorageRepoInstance := fileStorageRepo.MustAwsS3FileStorageRepo(fileStorageRepo.AwsS3FileStorageRepositoryParam{
		Conf:   fileStorageConf,
		Logger: logger,
	})
	fileStorageUCInstance := fileStorageUseCase.MustAwsS3FileStorageUseCase(fileStorageUseCase.AwsS3FileStorageUseCaseParam{
		Conf:   fileStorageConf,
		Logger: logger,
		Repo:   fileStorageRepoInstance,
	})

	return fileStorageUCInstance
}
