// Code scaffolded by goctl. Safe to edit.
package member

import (
	"context"

	domusecase "gateway/internal/model/member/domain/usecase"
	"gateway/internal/svc"
	"gateway/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

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

func NewGetMemberMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMemberMeLogic {
	return &GetMemberMeLogic{Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx}
}

func (l *GetMemberMeLogic) GetMemberMe() (*types.MemberMeData, error) {
	actor, err := actorOrErr(l.ctx)
	if err != nil {
		return nil, err
	}
	if l.svcCtx.MemberProfile == nil {
		return nil, errb.SysNotImplemented("member profile not configured")
	}
	dto, err := l.svcCtx.MemberProfile.GetByUID(l.ctx, &domusecase.GetMemberRequest{
		TenantID: actor.TenantID,
		UID:      actor.UID,
	})
	if err != nil {
		return nil, err
	}
	return memberDTOToTypes(dto), nil
}
