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 AttentionRepository extends JpaRepository<Attention, Integer> {

    /**
     * 根据用户ID，被关注ID和类型，得到对象
     * @param userId        用户ID
     * @param attentionId   被关注者ID
     * @param type          被关注者类型：1-医院（对应hospital表）
     * @return
     */
    @Query(value = "select * from attention where user_id = ? and attention_id = ? and type = ? and deleted = 0 limit 1", nativeQuery = true)
    Attention getAttention(int userId, int attentionId, int type);


    /**
     * 判断用户是否关注该类型（暂指医院）
     * @param userId        用户ID
     * @param attentionId   被关注者ID
     * @param type          被关注者类型：1-医院（对应hospital表）
     * @return
     */
    @Query(value = "select count(*) from attention where user_id = ? and attention_id = ? and type = ? and deleted = 0 limit 1", nativeQuery = true)
    int checkAttentionHospital(int userId, int attentionId, int type);


    /**
     * 判断用户是否关注该类型（暂指医院）
     * @param userId        用户ID
     * @param type          被关注者类型：1-医院（对应hospital表）
     * @return
     */
    @Query(value = "select * from attention where user_id = ? and type = ? and deleted = 0 ", nativeQuery = true)
    List<Attention> getAttentionList(int userId, int type);



}
