// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package svc

import (
	"sundynix-micro-go/app/file/api/internal/config"
	"sundynix-micro-go/app/file/rpc/fileservice"

	"github.com/minio/minio-go/v7"
	"github.com/minio/minio-go/v7/pkg/credentials"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/zrpc"
)

type ServiceContext struct {
	Config      config.Config
	FileRpc     fileservice.FileService
	MinioClient *minio.Client
}

func NewServiceContext(c config.Config) *ServiceContext {
	// 初始化MinIO客户端（上传需要在API层操作）
	minioClient, err := minio.New(c.Minio.Endpoint, &minio.Options{
		Creds:  credentials.NewStaticV4(c.Minio.AccessKeyId, c.Minio.AccessKeySecret, ""),
		Secure: c.Minio.UseSsl,
	})
	if err != nil {
		logx.Errorf("初始化MinIO客户端失败: %v", err)
		panic(err)
	}

	return &ServiceContext{
		Config:      c,
		FileRpc:     fileservice.NewFileService(zrpc.MustNewClient(c.FileRpc)),
		MinioClient: minioClient,
	}
}
