// 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 GetStorageConfigListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取存储配置列表
func NewGetStorageConfigListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetStorageConfigListLogic {
	return &GetStorageConfigListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetStorageConfigListLogic) GetStorageConfigList(req *types.StorageConfigListReq) (resp *types.StorageConfigListResp, err error) {
	respRpc, err := l.svcCtx.FileRpc.GetStorageConfigList(l.ctx, &fileservice.StorageConfigListReq{
		Current:  int32(req.Current),
		PageSize: int32(req.PageSize),
		Type:     req.Type,
		Name:     req.Name,
	})
	if err != nil {
		return nil, err
	}

	var list []types.StorageConfigInfo
	for _, item := range respRpc.List {
		list = append(list, types.StorageConfigInfo{
			Id:              item.Id,
			Type:            item.Type,
			Name:            item.Name,
			Endpoint:        item.Endpoint,
			AccessKeyId:     item.AccessKeyId,
			AccessKeySecret: item.AccessKeySecret,
			BucketName:      item.BucketName,
			BucketUrl:       item.BucketUrl,
			Region:          item.Region,
			IsDefault:       int(item.IsDefault),
			Status:          int(item.Status),
			Remark:          item.Remark,
		})
	}

	return &types.StorageConfigListResp{
		List:  list,
		Total: respRpc.Total,
	}, nil
}
