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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.other.infra.database.rds.dao.team.AdminRechargeAgentRelationDAO;
import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation;
import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 管理员充值代理关系Service实现.
 *
 * @author tf
 */
@Service
public class AdminRechargeAgentRelationServiceImpl extends
    BaseServiceImpl<AdminRechargeAgentRelationDAO, AdminRechargeAgentRelation> implements
    AdminRechargeAgentRelationService {

  @Override
  public List<AdminRechargeAgentRelation> getByUserId(Long userId) {
    return list(new LambdaQueryWrapper<AdminRechargeAgentRelation>()
        .eq(AdminRechargeAgentRelation::getUserId, userId));
  }

  @Override
  public boolean checkRechargeAgent(Long userId) {
    return count(new LambdaQueryWrapper<AdminRechargeAgentRelation>()
        .eq(AdminRechargeAgentRelation::getUserId, userId)) > 0;
  }

  @Override
  public void add(AdminRechargeAgentRelation relation) {
    save(relation);
  }

  @Override
  public IPage<AdminRechargeAgentRelation> pageRechargeAgentByAdmin(Long adminUserId, Page<AdminRechargeAgentRelation> page) {
      return page(page, new LambdaQueryWrapper<AdminRechargeAgentRelation>()
          .eq(AdminRechargeAgentRelation::getAdminUserId, adminUserId)
          .orderByDesc(AdminRechargeAgentRelation::getCreateTime));
  }

}
