package com.fs.doctor.mapper;

import java.util.List;
import com.fs.doctor.domain.DoctorLevelApply;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 讲者定级申请Mapper接口
 *
 * @author fs
 * @date 2025-12-30
 */
public interface DoctorLevelApplyMapper
{
    /**
     * 查询讲者定级申请
     *
     * @param id 讲者定级申请主键
     * @return 讲者定级申请
     */
    public DoctorLevelApply selectDoctorLevelApplyById(Long id);

    /**
     * 查询讲者定级申请列表
     *
     * @param doctorLevelApply 讲者定级申请
     * @return 讲者定级申请集合
     */
    public List<DoctorLevelApply> selectDoctorLevelApplyList(DoctorLevelApply doctorLevelApply);

    /**
     * 新增讲者定级申请
     *
     * @param doctorLevelApply 讲者定级申请
     * @return 结果
     */
    public int insertDoctorLevelApply(DoctorLevelApply doctorLevelApply);

    /**
     * 修改讲者定级申请
     *
     * @param doctorLevelApply 讲者定级申请
     * @return 结果
     */
    public int updateDoctorLevelApply(DoctorLevelApply doctorLevelApply);

    /**
     * 删除讲者定级申请
     *
     * @param id 讲者定级申请主键
     * @return 结果
     */
    public int deleteDoctorLevelApplyById(Long id);

    /**
     * 批量删除讲者定级申请
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDoctorLevelApplyByIds(Long[] ids);
    @Update("update doctor_level_apply " +
            "set audit_instance_id = #{auditInstanceId} " +
            "where id = #{id}")
    void updateDoctorLevelApplyAuditInstanceId(@Param("id")Long id,@Param("auditInstanceId") Long auditInstanceId);


    @Select("select * from doctor_level_apply where doctor_id=#{doctorId}")
    List<DoctorLevelApply> selectByDoctorId(@Param("doctorId") String doctorId);

    long checkPendingApplyCount(String doctorId);


    /**
     * 更新form_id（回填）
     */
    @Update("UPDATE doctor_level_apply SET form_id = #{formId} WHERE id = #{id}")
    void updateFormId(@Param("id") Long id, @Param("formId") Long formId);

    /**
     * 根据ID获取动态表名（如果需要）
     */
    @Select("SELECT sv.table_name FROM doctor_level_apply da " +
            "LEFT JOIN survey_questionnaire_version sv ON da.version_id = sv.id " +
            "WHERE da.id = #{id}")
    String getTableNameByApplyId(@Param("id") Long id);
}
