package com.yaoai.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yaoai.domain.entity.TenantMember;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Optional;

@Mapper
public interface TenantMemberMapper extends BaseMapper<TenantMember> {

    default List<TenantMember> findByTenant(Long tenantId) {
        return selectList(Wrappers.<TenantMember>lambdaQuery()
                .eq(TenantMember::getTenantId, tenantId)
                .orderByAsc(TenantMember::getJoinedAt));
    }

    default Optional<TenantMember> findByTenantAndUser(Long tenantId, Long userId) {
        return Optional.ofNullable(selectOne(Wrappers.<TenantMember>lambdaQuery()
                .eq(TenantMember::getTenantId, tenantId)
                .eq(TenantMember::getUserId, userId)));
    }
}
