package com.red.circle.other.infra.database.rds.service.team.impl;

import com.red.circle.framework.mybatis.constant.PageConstant;
import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.other.infra.database.rds.dao.team.TeamManagerInfoDAO;
import com.red.circle.other.infra.database.rds.entity.team.TeamManagerInfo;
import com.red.circle.other.infra.database.rds.service.team.TeamManagerInfoService;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.springframework.stereotype.Service;

/**
 * 团队经理服务实现.
 */
@Service
public class TeamManagerInfoServiceImpl
    extends BaseServiceImpl<TeamManagerInfoDAO, TeamManagerInfo>
    implements TeamManagerInfoService {

  @Override
  public boolean checkManager(Long userId) {
    return Objects.nonNull(query()
        .eq(TeamManagerInfo::getUserId, userId)
        .last(PageConstant.LIMIT_ONE)
        .getOne());
  }

  @Override
  public TeamManagerInfo getByUserId(Long userId) {
    return query()
        .eq(TeamManagerInfo::getUserId, userId)
        .last(PageConstant.LIMIT_ONE)
        .getOne();
  }

  @Override
  public void deleteById(Long id) {
    delete().eq(TeamManagerInfo::getId, id).execute();
  }

  @Override
  public List<TeamManagerInfo> listByUserIds(Set<Long> userIds) {
    if (userIds == null || userIds.isEmpty()) {
      return new ArrayList<>();
    }

    return query()
        .in(TeamManagerInfo::getUserId, userIds)
        .list();
  }

}
