package com.jeesharp.business.modules.member.service.impl;

import com.jeesharp.business.modules.member.entity.Member;
import com.jeesharp.business.modules.member.service.MemberService;
import com.jeesharp.framework.memberauth.user.BaseMemberUser;
import com.jeesharp.framework.memberauth.user.MemberUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

/**
 * 移动端会员用户服务实现
 * 供 MemberAuthUtils 根据 loginId（即 memberId）获取完整会员信息
 *
 * @author jeesharp
 */
@Service
@RequiredArgsConstructor
public class MobileMemberUserServiceImpl implements MemberUserService {

    @Autowired
    private  MemberService memberService;

    @Override
    @Nullable
    public BaseMemberUser getMemberUser(String loginId) {
        if (loginId == null || loginId.isEmpty()) {
            return null;
        }
        try {
            Member member = memberService.get(loginId);
            return new BaseMemberUser()
                    .setId(member.getId())
                    .setName(member.getNickname() != null ? member.getNickname() : member.getMobile());
        } catch (Exception e) {
            return null;
        }
    }
}
