package auth

import (
	"context"

	memberusecase "haixun-backend/internal/model/member/domain/usecase"
	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"
)

type RegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{ctx: ctx, svcCtx: svcCtx}
}

func (l *RegisterLogic) Register(req *types.AuthRegisterReq) (*types.AuthTokenData, error) {
	_, token, err := l.svcCtx.Member.Register(l.ctx, memberusecase.RegisterRequest{
		TenantID:    req.TenantID,
		Email:       req.Email,
		Password:    req.Password,
		DisplayName: req.DisplayName,
		Language:    req.Language,
	})
	return toAuthTokenData(token), err
}
