package com.ycwl.basic.mapper;

import com.ycwl.basic.model.pc.task.entity.TaskEntity;
import com.ycwl.basic.model.pc.video.entity.MemberVideoEntity;
import com.ycwl.basic.model.pc.video.entity.VideoEntity;
import com.ycwl.basic.model.pc.video.req.VideoReqQuery;
import com.ycwl.basic.model.pc.video.resp.VideoRespVO;
import lombok.NonNull;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * @Author：longbinbin
 * @Date：2024/12/2 15:27
 * 成片
 */
@Mapper
public interface VideoMapper {
    List<VideoRespVO> list(VideoReqQuery videoReqQuery);
    VideoRespVO getById(Long id);
    int add(VideoEntity task);
    int deleteById(Long id);
    int update(VideoEntity task);
    int updateMeta(VideoEntity task);

    VideoEntity findByTaskId(@NonNull Long taskId);


    int addRelation(MemberVideoEntity source);
    int addRelations(List<MemberVideoEntity> list);
    int updateRelation(MemberVideoEntity memberVideoEntity);

    List<VideoRespVO> queryByRelation(VideoReqQuery videoReqQuery);

    List<MemberVideoEntity> userFaceTemplateVideo(Long userId, Long faceId, Long templateId);

    MemberVideoEntity queryRelationByMemberTask(Long userId, Long taskId);
    List<MemberVideoEntity> listRelationByTask(Long taskId);
    List<MemberVideoEntity> listRelationByFace(Long faceId);
    List<MemberVideoEntity> listRelationByFaceAndTemplate(Long faceId, Long templateId);

    List<TaskEntity> listTaskByScenicRelation(Long userId, Long scenicId);

    MemberVideoEntity queryUserVideo(Long userId, Long videoId);

    int updateRelationWhenTaskSuccess(Long taskId, Long videoId, int isBuy);

    List<MemberVideoEntity> listRelationByCreateTime(Date startTime, Date endTime);

    VideoEntity getEntity(Long videoId);

    int deleteNotBuyRelations(Long scenicId, Date endDate);

    int deleteNotBuyFaceRelations(Long userId, Long faceId);

    int deleteUselessVideo();

    int updateMemberIdByFaceId(Long faceId, Long memberId);

    /**
     * 查询指定视频是否存在已购买记录
     * @param videoId 视频ID
     * @return 已购买记录数量
     */
    int countBuyRecordByVideoId(Long videoId);

    /**
     * 通过faceId和templateId（可选）查询最新的视频记录
     * @param faceId 人脸ID
     * @param templateId 模板ID（可选）
     * @return 最新的视频记录
     */
    VideoRespVO queryLatestByFaceIdAndTemplateId(@NonNull Long faceId, Long templateId);
}
