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

package file

import (
	"context"

	"github.com/zeromicro/go-zero/core/logx"
	"sundynix-micro-go/app/file/api/internal/svc"
	"sundynix-micro-go/app/file/api/internal/types"
	"sundynix-micro-go/app/file/rpc/fileservice"
)

type UpdateStorageConfigLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 更新存储配置
func NewUpdateStorageConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateStorageConfigLogic {
	return &UpdateStorageConfigLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateStorageConfigLogic) UpdateStorageConfig(req *types.UpdateStorageConfigReq) error {
	_, err := l.svcCtx.FileRpc.UpdateStorageConfig(l.ctx, &fileservice.UpdateStorageConfigReq{
		Id:              req.Id,
		Type:            req.Type,
		Name:            req.Name,
		Endpoint:        req.Endpoint,
		AccessKeyId:     req.AccessKeyId,
		AccessKeySecret: req.AccessKeySecret,
		BucketName:      req.BucketName,
		BucketUrl:       req.BucketUrl,
		Region:          req.Region,
		Status:          int32(req.Status),
		Remark:          req.Remark,
	})
	if err != nil {
		return err
	}

	return nil
}
