package org.qinan.safetyeval.infrastructure.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.qinan.safetyeval.infrastructure.dataobject.QualFilingChangeDetailDO;

import java.util.List;

@Mapper
public interface QualFilingChangeDetailMapper extends BaseMapper<QualFilingChangeDetailDO> {

    @Select("SELECT d.* FROM qual_filing_change_detail d "
            + "INNER JOIN qual_filing_change c ON d.change_id = c.id "
            + "WHERE c.filing_id = #{filingId} AND d.delete_enum = 'false' AND c.delete_enum = 'false' "
            + "ORDER BY d.create_time DESC")
    List<QualFilingChangeDetailDO> selectByFilingId(@Param("filingId") Long filingId);

    @Select("SELECT COUNT(1) FROM qual_filing_change_detail d "
            + "INNER JOIN qual_filing_change c ON d.change_id = c.id "
            + "WHERE c.filing_id = #{filingId} AND d.delete_enum = 'false' AND c.delete_enum = 'false'")
    int countByFilingId(@Param("filingId") Long filingId);
}
