package cn.reghao.tnb.content.app.vod.db.mapper;

import cn.reghao.file.api.dto.VideoMeta;
import cn.reghao.jutil.jdk.web.db.BaseMapper;
import cn.reghao.jutil.jdk.web.db.Page;
import cn.reghao.tnb.common.db.GroupCount;
import cn.reghao.tnb.content.api.dto.VideoPostCard;
import cn.reghao.tnb.content.app.vod.model.dto.VideoInfoUpdate;
import cn.reghao.tnb.content.app.vod.model.dto.VideoScopeUpdate;
import cn.reghao.tnb.content.app.vod.model.query.VideoQuery;
import cn.reghao.tnb.content.app.vod.model.po.BannerVideo;
import cn.reghao.tnb.content.app.vod.model.po.VideoPost;
import cn.reghao.tnb.content.app.vod.model.vo.*;
import cn.reghao.tnb.content.app.vod.model.dto.SearchCriteria;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

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

/**
 * @author reghao
 * @date 2021-11-22 10:41:35
 */
@Mapper
public interface VideoPostMapper extends BaseMapper<VideoPost> {
    void updateVideoScope(VideoScopeUpdate videoScopeUpdate);
    void updateVideoInfo(VideoInfoUpdate videoInfoUpdate);
    void updateVideoCover(@Param("videoId") String videoId, @Param("coverUrl") String coverUrl);
    void updateVideoFile(@Param("videoId") String videoId, @Param("videoMeta") VideoMeta videoMeta);
    void updateVideoStatus(@Param("videoId") String videoId, @Param("status") int status);
    void updateVideoPublish(VideoPost videoPost);
    void updateVideoCached(@Param("videoId") String videoId,
                           @Param("videoMeta") VideoMeta videoMeta,
                           @Param("channelCode") int channelCode);
    void deleteByVideoId(String videoId);

    /* 根据条件分页获取 */
    int countByCriteria(VideoQuery videoQuery);
    List<VideoPost> findVideoPostByPage(@Param("page") Page page, @Param("videoQuery") VideoQuery videoQuery);
    List<VideoPostCard> findVideoCardByPage(@Param("page") Page page, @Param("videoQuery") VideoQuery videoQuery);

    int countAdminVideo(VideoQuery videoQuery);
    List<VideoPost> findAdminVideoByPage(@Param("page") Page page, @Param("videoQuery") VideoQuery videoQuery);

    List<VideoPostCard> findByNextVideos(@Param("videoQuery") VideoQuery videoQuery, @Param("publishAt") LocalDateTime publishAt);

    VideoPost findByVideoId(String videoId);
    VideoDetail findVideoPostDetail(VideoQuery videoQuery);

    List<VideoPostCard> findVideoCardByVideoIds(List<String> videoIds);
    List<VideoPostCard> findByUserIds(@Param("userIds") List<Long> userIds, @Param("pageSize") int pageSize, @Param("nextId") int nextId);
    int countBySearchCriteria(SearchCriteria searchCriteria);
    List<VideoPost> findSearchCriteriaByPage(@Param("page") Page page, @Param("searchCriteria") SearchCriteria searchCriteria);
    List<VideoPost> findAllById(@Param("pageSize") int pageSize, @Param("nextId") int nextId);
    @Deprecated
    List<BannerVideo> findBannerVideos(List<String> videoIds);
    List<GroupCount> findPublishByPost();
    List<GroupCount> findPublishByVideo();
    List<GroupCount> findPublishByImage();
    List<String> findRandomVideoIds(@Param("scopes") List<Integer> scopes, @Param("size") int size);
    List<String> findShortVideo(List<Integer> scopes);
    List<VideoPost> findGroupByUserAndCategory(int categoryPid);
    VideoPost findUserAndCategory(@Param("publishBy") long publishBy, @Param("categoryId") int categoryId);
    List<VideoPost> findByTitle(String title);
}
