package com.storlead.user.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.storlead.framework.common.constant.CommonConstant;
import com.storlead.framework.mybatis.service.impl.MyBaseServiceImpl;
import com.storlead.user.mapper.TenantUserMapper;
import com.storlead.user.pojo.entity.TenantUserEntity;
import com.storlead.user.service.ITenantUserService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class TenantUserServiceImpl extends MyBaseServiceImpl<TenantUserMapper, TenantUserEntity>
        implements ITenantUserService {

    @Override
    public TenantUserEntity getByTenantIdAndUserId(Long tenantId, Long userId) {
        if (tenantId == null || userId == null) {
            return null;
        }
        return getOne(Wrappers.<TenantUserEntity>lambdaQuery()
                .eq(TenantUserEntity::getTenantId, tenantId)
                .eq(TenantUserEntity::getUserId, userId)
                .eq(TenantUserEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
                .last("LIMIT 1"));
    }

    @Override
    public List<TenantUserEntity> listByEnterpriseId(Long enterpriseId) {
        if (enterpriseId == null) {
            return Collections.emptyList();
        }
        return list(Wrappers.<TenantUserEntity>lambdaQuery()
                .eq(TenantUserEntity::getEnterpriseId, enterpriseId));
    }
}
