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 DoctorRepository extends JpaRepository<Doctor, Integer> {

    /**
     * 判断是否关联某个医生
     *
     * @param doctorId
     * @param unionDoctorId
     * @return
     */
    @Query(value = "SELECT COUNT(1) FROM union_doctor WHERE ((doctor_id = ? AND union_doctor_id = ?) OR (doctor_id = ? AND union_doctor_id = ?)) AND is_deleted =0 AND status = 1 limit 1", nativeQuery = true)
    int checkUnionDoctor(Integer doctorId, Integer unionDoctorId, Integer unionDoctorId2, Integer doctorId2);

    @Query(value = "SELECT * FROM doctor WHERE is_deleted = 0", nativeQuery = true)
    List<Doctor> findAllNotDelete();

    @Query(value = "SELECT * FROM doctor WHERE id = ? AND is_deleted = 0 AND status = 0 limit 1", nativeQuery = true)
    Doctor findNormalDoctorById(int doctorId);

    @Query(value = "SELECT * FROM doctor WHERE id = ? AND is_deleted = 0 limit 1", nativeQuery = true)
    Doctor findNotDeletedDoctorById(int doctorId);
}
