package auth

import (
	"context"

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

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

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

func (l *LoginLogic) Login(req *types.AuthLoginReq) (*types.AuthTokenData, error) {
	_, token, err := l.svcCtx.Member.Login(l.ctx, memberusecase.LoginRequest{
		TenantID: req.TenantID,
		Email:    req.Email,
		Password: req.Password,
	})
	return toAuthTokenData(token), err
}
