package com.sqx.modules.course.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sqx.modules.course.entity.CourseDetails;
import com.sqx.modules.course.vo.CourseDetailsSetVo;
import com.sqx.modules.course.vo.CourseDetailsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
@CacheConfig
public interface CourseDetailsDao extends BaseMapper<CourseDetails> {
    /**
     * @param courseId       剧的id
     * @param isPrice        是否收费 true 收费
     * @param price          全剧价格
     * @param wholesalePrice 10集价格
     */
    @Cacheable(cacheNames = "courseSets", key = "#courseId + '-' + #isPrice")
    List<CourseDetailsSetVo> courseSets(@Param("courseId") Long courseId, Integer isPrice, BigDecimal wholesalePrice);

    List<CourseDetails> findByCourseId(@Param("id") Long id, @Param("userId") Long userId);

    List<CourseDetails> selectCoursePageByCourseId(@Param("id") Long id, @Param("good") Integer good);

    List<CourseDetails> findByCourseIdNotUrl(@Param("id") Long id, @Param("userId") Long userId);

    /**
     * 更新播放数量
     *
     * @param courseId courseId  必须有值
     * @param courseDetailsId courseDetailsId 必须有值
     * @param state 1为 ViewCount 其它 为 PlayCompleteCount
     */
    void updateViewCount(@Param("courseId") Long courseId,@Param("courseDetailsId") Long courseDetailsId, @Param("state") int state);

    int deleteCourseDetails(String[] ids);


    /**
     * 播放数
     * 点赞数
     * 总集数
     */
    Map<String, Object> countCourse(Long courseId);

    @Cacheable(cacheNames = "courseCount", key = "#courseId")
    Integer countCourseByCourseId(Long courseId);

    List<CourseDetails> countByCourseId(@Param("courseIdList")Set<Long> courseIdList);
}
