package com.test.bijihoudaun.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.test.bijihoudaun.entity.MarkdownFile;
import com.test.bijihoudaun.entity.MarkdownFileVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MarkdownFileMapper extends BaseMapper<MarkdownFile> {

    @Select("SELECT mf.*, g.grouping as groupingName " +
            "FROM markdown_file mf " +
            "LEFT JOIN grouping g ON mf.grouping_id = g.id " +
            "ORDER BY mf.updated_at DESC " +
            "LIMIT #{limit}")
    List<MarkdownFileVO> selectRecentWithGrouping(@Param("limit") int limit);

    @Select("SELECT mf.*, g.grouping as groupingName " +
            "FROM markdown_file mf " +
            "LEFT JOIN grouping g ON mf.grouping_id = g.id " +
            "WHERE mf.grouping_id = #{groupingId} " +
            "ORDER BY mf.updated_at DESC")
    List<MarkdownFileVO> selectByGroupingIdWithGrouping(@Param("groupingId") String groupingId);
}
