package com.ycwl.basic.mapper;

import com.ycwl.basic.model.pc.source.entity.MemberSourceEntity;
import com.ycwl.basic.model.pc.source.entity.SourceEntity;
import com.ycwl.basic.model.pc.source.entity.SourceWatermarkEntity;
import com.ycwl.basic.model.pc.source.req.SourceReqQuery;
import com.ycwl.basic.model.pc.source.resp.SourceRespVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Date;
import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/2 11:21
 * 视频源
 */
@Mapper
public interface SourceMapper {
    List<SourceRespVO> list(SourceReqQuery sourceReqQuery);

    SourceRespVO getById(Long id);
    SourceRespVO userGetById(Long id, Long userId);

    List<SourceEntity> listBySampleIds(List<Long> sourceIds);

    int add(SourceEntity source);

    int deleteById(Long id);

    int update(SourceEntity source);

    /**
     * @param sourceReqQuery
     * @return
     */
    List<SourceRespVO> listGroupByType(SourceReqQuery sourceReqQuery);

    /**
     * 用户素材数量
     *
     * @param userId
     * @return
     */
    int countByMemberId(String userId);

    List<SourceEntity> listVideoBySampleIds(List<Long> sampleId);

    SourceEntity findBySampleId(Long faceSampleId);

    int addRelation(MemberSourceEntity source);

    List<SourceRespVO> listUser(SourceReqQuery sourceReqQuery);
    Integer countUser(SourceReqQuery sourceReqQuery);
    SourceRespVO listUserOne(Long userId, Long sourceId);

    int addRelations(List<MemberSourceEntity> list);

    List<MemberSourceEntity> filterExistingRelations(List<MemberSourceEntity> list);

    boolean sourceExists(Long sourceId);

    List<MemberSourceEntity> filterValidSourceRelations(List<MemberSourceEntity> list);

    int updateRelation(MemberSourceEntity memberSourceEntity);
    int freeRelations(List<Long> ids, int type);

    List<SourceRespVO> queryByRelation(SourceReqQuery sourceReqQuery);

    SourceEntity querySameVideo(Long faceSampleId, Long deviceId);

    int hasRelationTo(Long memberId, Long sourceId, int type);

    List<SourceEntity> listVideoByScenicFaceRelation(Long scenicId, Long faceId);
    List<SourceEntity> listVideoByFaceRelation(Long faceId);

    List<SourceEntity> listImageByFaceRelation(Long faceId);
    List<MemberSourceEntity> listByFaceRelation(Long faceId, Integer type);

    SourceEntity getEntity(Long id);

    int deleteNotRelateSource(int type, Date endDate);

    int deleteNotBuyRelations(Long scenicId, Date endDate);

    int deleteNotBuyFaceRelation(Long userId, Long faceId);
    List<SourceWatermarkEntity> listSourceWatermark(List<Long> sourceIds, Long faceId, String watermarkType);

    void addSourceWatermark(Long sourceId, Long faceId, String type, String url);

    int deleteUselessSource();
    
    int updateMemberIdByFaceId(Long faceId, Long memberId);
    
    /**
     * 根据faceId查询type=2的source列表
     * @param faceId 人脸ID
     * @return type=2的source列表
     */
    List<SourceEntity> listImageSourcesByFaceId(Long faceId);

    /**
     * 从ZT-Source消息添加素材
     * @param source 素材实体
     * @return 影响行数
     */
    int addFromZTSource(SourceEntity source);

    SourceEntity getBySampleIdAndType(Long faceSampleId, Integer type);
}
