package cn.fateverse.admin.dubbo;

import cn.fateverse.admin.facade.UserFacade;
import cn.fateverse.admin.vo.UserVo;
import cn.fateverse.common.core.entity.UserDetail;
import cn.fateverse.common.core.exception.CustomException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

/**
 * @author Clay
 * @date 2023-02-20
 */
@Slf4j
@DubboService
@RequiredArgsConstructor
public class DubboUserServiceImpl implements DubboUserService {

    private final UserFacade userFacade;


    @Override
    public UserVo getUserByUsername(String username) {
        log.info("用户登录:{}", username);
        return userFacade.searchByUserName(username);
    }

    @Override
    public UserVo getUserByUserId(Long userId) {
        return userFacade.searchByUserId(userId);
    }

    @Override
    public List<UserVo> searchUserListByRoleIds(List<Long> roleIds) {
        if (roleIds.isEmpty()) {
            throw new CustomException("角色id不能为空");
        }
        return userFacade.searchListByRoleIds(roleIds);
    }

    @Override
    public List<UserVo> searchUserListByUserIds(List<Long> userIds) {
        if (userIds.isEmpty()) {
            throw new CustomException("用户id不能为空");
        }
        return userFacade.searchByUserIds(userIds);
    }

    @Override
    public List<UserVo> searchUserByDeptIds(List<Long> deptIds) {
        if (deptIds.isEmpty()) {
            throw new CustomException("部门id不能为空");
        }
        return userFacade.searchByDeptIds(deptIds);
    }

    @Override
    public List<Long> searchAllUserIds() {
        return userFacade.searchAllUserIds();
    }

    @Override
    public UserDetail getUserDetailsByUserName(String userName) {
        return userFacade.getUserDetailsByUserName(userName);
    }
}
