package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.entity.Course;
import com.zhentao.mapper.CourseMapper;
import com.zhentao.service.CourseService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 课程服务实现类
 */
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {
    
    /**
     * 获取推荐课程列表
     * 
     * @return 推荐课程列表
     */
    @Override
    public List<Course> getRecommendedCourses() {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Course::getIsRecommended, 1)
               .orderByDesc(Course::getRating)
               .orderByDesc(Course::getParticipants);
        return list(wrapper);
    }
    
    /**
     * 获取所有课程列表
     * 
     * @return 课程列表
     */
    @Override
    public List<Course> getAllCourses() {
        LambdaQueryWrapper<Course> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Course::getIsRecommended)
               .orderByDesc(Course::getRating)
               .orderByDesc(Course::getParticipants);
        return list(wrapper);
    }
    
    /**
     * 根据ID获取课程详情
     * 
     * @param id 课程ID
     * @return 课程详情
     */
    @Override
    public Course getCourseById(Integer id) {
        return getById(id);
    }
}

