package com.friday.custody.service.basicService.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.friday.custody.dao.TenantEmailAuthorizationInfoDao;
import com.friday.custody.entity.TenantEmailAuthorizationInfoEntity;
import com.friday.custody.service.basicService.TenantEmailAuthorizationInfoService;
import com.friday.custody.utils.PageUtils;
import com.friday.custody.utils.Query;
import com.friday.operation.api.custody.vo.AuthorizationEmailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;


@Service("tenantEmailAuthorizationInfoService")
@Slf4j
public class TenantEmailAuthorizationInfoServiceImpl extends ServiceImpl<TenantEmailAuthorizationInfoDao, TenantEmailAuthorizationInfoEntity> 
        implements TenantEmailAuthorizationInfoService {

    @Autowired
    private TenantEmailAuthorizationInfoDao tenantEmailAuthorizationInfoDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TenantEmailAuthorizationInfoEntity> page = this.page(
                new Query<TenantEmailAuthorizationInfoEntity>().getPage(params),
                new QueryWrapper<TenantEmailAuthorizationInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<AuthorizationEmailVO> selectAllEmailConfigList() {
        return tenantEmailAuthorizationInfoDao.selectAllEmailConfigList();
    }

    public List<TenantEmailAuthorizationInfoEntity> queryByTenantName(String tenantName, String trustNo) {
        QueryWrapper<TenantEmailAuthorizationInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tenant_name", tenantName);
        queryWrapper.eq("trust_no", trustNo);
        queryWrapper.eq("is_deleted", 0);

        return baseMapper.selectList(queryWrapper);
    }
    /*public Integer queryExistenceByTenantName(String tenantName, String trustNo) {
        QueryWrapper<TenantEmailAuthorizationInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("tenant_name", tenantName);
        queryWrapper.eq("trust_no", trustNo);
        List<TenantEmailAuthorizationInfoEntity> tenantEmailAuthorizationInfoEntities = baseMapper.selectList(queryWrapper);
        return tenantEmailAuthorizationInfoEntities.size();
    }*/

}