package com.storlead.sales.mail.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.storlead.sales.mail.entity.EmailsEntity;
import com.storlead.framework.mybatis.mapper.MyBaseMapper;
import com.storlead.sales.mail.pojo.MailDTO;
import com.storlead.sales.mail.pojo.MailListDTO;
import com.storlead.sales.mail.pojo.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 邮件表 Mapper 接口
 * </p>
 *
 * @author chenkq
 * @since 2024-05-28
 */
public interface EmailsMapper extends MyBaseMapper<EmailsEntity> {

    void updateCleanBindCustomerMail();

    void updateBindCustomerMail();

    void updateBindLiaisonMail();

    /**
     * 绑定客户邮件关系
     * @param mailId
     * @param mailAddress
     * @param userId
     */
    Set<Long> getMailCustomerIdByMailIdAndUserId(@Param("mailId") Long mailId, @Param("mailAddress") String mailAddress, @Param("userId") Long userId);

    /**
     * 绑定联系人邮箱和客户关系
     * @param mailId
     * @param mailAddress
     * @param userId
     */
    List<MailLiaisonVO> getLiaisonMailCustomerIdByMailIdAndUserId(@Param("mailId") Long mailId, @Param("mailAddress") String mailAddress, @Param("userId") Long userId);

    void bindMailCustomerIdByMailId(@Param("mailId") Long mailId,@Param("customerIds") String customerId,@Param("liaisonIds") String liaisonIds);

    EmailsEntity getEmailsByMessageId(@Param("messageId") String messageId,@Param("folder") String folder,@Param("smtpPopId") Long smtpPopId);

    List<String> getEmailMessageIdsByMessageIds(@Param("messageIds") List<String> messageIds,@Param("folder") String folder,@Param("smtpPopId") Long smtpPopId);

    String getEmailMessageIdsByMessageId(@Param("messageId") String messageId,@Param("folder") String folder,@Param("smtpPopId") Long smtpPopId);

    Long getEmailsIdByMessageId(@Param("messageId") String messageId,@Param("smtpPopId") Long smtpPopId);

    IPage<EmailsEntity> pageList(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);


    IPage<EmailsEntity> pageListCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);

    IPage<EmailsEntity> pageListAllCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);

    IPage<EmailsEntity> pageListNew(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);

    IPage<EmailsEntity> pageListNewAllCus(IPage<EmailsEntity> page, @Param("dto") MailDTO dto);

    /**
     * 汇总邮件数量
     * @param stmpPopIdk
     * @param ownerBy
     * @return
     */
    NewMailCountTipVO countMailSummaryNum(Long smtpPopId, Long ownerBy);

    /**
     * 汇总未跟进数
     * @param stmpPopId
     * @param ownerBy
     * @return
     */
    NewMailCountTipVO countCustomerAndClueNumber(Long smtpPopId, Long ownerBy);

    /**
     * 汇总客户邮件数
     * @param stmpPopId
     * @param ownerBy
     * @return
     */
    NewMailCountTipVO countCustomerFollowUpMailNum(Long smtpPopId, Long ownerBy);

    LocalDateTime selectCustomerLastFollowUpTime(Long customerId);

    List<EmailsEntity> selectDelayDeleteMail();

    List<UserClickTitleVO> selectUserClickTitle(@Param("ownerBy") Long ownerBy,@Param("title") String title);

    IPage<CustomerEmailVo> selectCustomerEmailPage(Page<CustomerEmailVo> page,@Param("query") MailListDTO dto);

    List<Long> selectCusIdByMailId(@Param("mailIdls") List<Long> mailIdls);

    List<CustomerMailVO> selectCusInfoByCusId(@Param("customerIdls") List<Long> customerIdls);

    Integer countSmtpMailCount(@Param("userId") Long userId);
}
