package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DoctorInfoAuditRepository extends JpaRepository<DoctorInfoAudit, Integer> {
    @Query(value = "select * from doctor_info_audit where doctor_id = ? and deleted = 0 order by id desc limit 1;", nativeQuery = true)
    DoctorInfoAudit getDoctorInfoAudit(int doctorId);

    @Query(value = "select * from doctor_info_audit where doctor_id = ? and audit_status = 1 and deleted = 0 order by create_time desc limit 1;", nativeQuery = true)
    DoctorInfoAudit getLatestApprovedDoctorInfoAudit(int doctorId);

    /**
     * 获取医生最新的认证审核资料
     * @param doctorId
     * @return
     */
    @Query(value = "select * from doctor_info_audit where doctor_id = ? and audit_type = 1 and deleted = 0 order by create_time desc limit 1;", nativeQuery = true)
    DoctorInfoAudit getCertificationAudit(int doctorId);

    /**
     * 获取所有正在认证的医生信息
     * @return
     */
    @Query(value = "SELECT * FROM doctor_info_audit WHERE audit_type = 1 and audit_status = 0 and deleted = 0", nativeQuery = true)
    List<DoctorInfoAudit> findAllDoctorInfoAuditing();
}
