package com.storlead.sales.service.customer;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.storlead.framework.auth.vo.LoginUser;
import com.storlead.framework.common.result.Result;
import com.storlead.framework.mybatis.service.MyBaseService;
import com.storlead.sales.pojo.dto.customer.*;
import com.storlead.sales.pojo.entity.customer.CustomerCompanyEntity;
import com.storlead.sales.pojo.entity.customer.CustomerEntity;
import com.storlead.sales.pojo.entity.customer.LiaisonEntity;
import com.storlead.sales.pojo.vo.customer.CustomerAllVO;
import com.storlead.sales.pojo.vo.customer.CustomerListVO;
import com.storlead.sales.pojo.vo.customer.CustomerVO;
import com.storlead.sales.enums.ResourceTypeEnum;

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

/**
 * <p>
 * 客户基本信息表 服务类
 * </p>
 *
 * @author YPZ
 * @since 2024-04-12
 */
public interface CustomerService extends MyBaseService<CustomerEntity> {

    /***
      * @Description: 添加客户/线索
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/4/12 17:40
      */
    Result<?> addCustomer(CustomerAddDTO customerAddDTO);

    /***
      * @Description: 校验客户/线索是否可以添加
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/10/10 12:20
      */
    Result<?> addCheck(CustomerAddDTO customerAddDTO);

    Result<?> addCheckNew(CustomerAddDTO customerAddDTO);

    Result<?> addNoCheckCustomer(CustomerAddDTO customerAddDTO);

    List<CustomerEntity> assembleCustomerLs(List<CustomerAddDTO> dtos);

    List<LiaisonEntity> assembleLiaisonLs(List<CustomerAddDTO> dtos);

    List<CustomerCompanyEntity> assembleCustomerCompanyLs(List<CustomerAddDTO> dtos);

    Result<IPage<CustomerListVO>> selectListVO(CustomerSearchDTO customerSearchDTO);
    IPage<?> selectSimpleListVO(CustomerSearchSearchDTO customerSearchSearchDTO,String resourceType);

    List<Long> getCustomerIdList(Long userId);

    Result<?> editCustomer(CustomerAddDTO customerAddDTO);

    CustomerVO getCustomerVOById(Long id);

    CustomerEntity getCustomerIdByName(String customerName);

    CustomerEntity getCustomerIdByNameAndOwnerBy(String customerName,Long ownerBy);

    /***
      * @Description: 根据客户id获取客户信息
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/5/17 11:31
      */
    Map<Long, CustomerEntity> getCustomerMap(Set<Long> customerIdList);

    /**
     * 获取客户集合
     * @param customerIdList
     * @return
     */
    List<CustomerEntity> listCustomers(List<Long> customerIdList);
    /***
      * @Description: 合并客户
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/5/21 15:53
      */
    Result<?> mergeCustomer(CustomerMergeDTO customerMergeDTO);

    /***
      * @Description: 线索转为客户
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/6/3 15:07
      */
    Result<?> convertToCustomer(CustomerConvertDTO customerConvert);

    /***
      * @Description: 领取线索
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/6/3 15:33
      */
    Result<?> collectClues(CustomerCollectCluesDTO collectCluesDTO);

    /***
      * @Description: 分配线索
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/6/3 15:44
      */
    Result<?> assignClues(CustomerAssignCluesDTO customerAssignCluesDTO);

    /***
      * @Description: 移入公海
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/6/7 12:00
      */
    Result<?> forReson(CustomerForReasonDTO customerForReason);

    /***
      * @Description: 客户添加协作人员
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/6/12 16:32
      */
    Result<?> collaborator(CustomerCollaboratorDTO customerCollaboratorDTO);

    CustomerAllVO getCustomerAllVOById(CustomerSearchDTO customerSearchDTO);

    /***
      * @Description: 删除客户及客户关联的全部数据（商机、订单、联系人、跟进记录、任务、工单、报价单）
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/9/14 16:15
      */
    boolean glAllDelete(Long id);

    boolean glAllListDelete(List<Long> idList);


    Boolean maxMemberNum(Integer num, Long ownerBy, String resourceType);

    /***
      * @Description: 根据邮件更新客户跟进时间
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/11/1 15:37
      */
    void updateFollowUpTimeByEmail(Set<String> emailsList, LocalDateTime currentTime);
    /***
      * @Description: 通过客户id查客户及联系人的所有邮箱
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2024/11/19 15:26
      */
    Set<String> findEmailByCustomerId(Long customerId);

    /***
      * @Description: 添加官网线索
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2025/3/6 17:13
      */
    void addWebClue();

    List<String> assembleLiaisonMails(LiaisonEntity liaisonEntity);

    List<String> assembleCustomerMails(CustomerCompanyEntity customerEntity);

    /***
      * @Description: 更新客户补充未跟进天数
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2025/3/6 17:13
      */
    void updateCustomerNoFollowUpDate(List<Long> idList);

    Result<?> chengeClusStatus(CustomerAddDTO customerAddDTO);

    /***
      * @Description: 替换客户协作人员
      * @Param:
      * @return:
      * @Author: YPZ
      * @Date: 2025/12/24 14:44
      */
    void replaceCollaborator(CustomerTransferDTO customerTransferDTO);
}
