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 SnsUserInfoRepository extends JpaRepository<SnsUserInfo, Integer> {

    @Query(value = "select * from sns_user_info where union_id = ? and terminal = ? and deleted = 0 limit 1;", nativeQuery = true)
    SnsUserInfo getSnsUserInfoByUnionId(String unionId, int terminal);

    @Query(value = "select * from sns_user_info where union_id = ? and deleted = 0;", nativeQuery = true)
    List<SnsUserInfo> getSnsUserInfoListByUnionId(String unionId);

    @Query(value = "select * from sns_user_info where user_id = ? and terminal = ? and deleted = 0 limit 1;", nativeQuery = true)
    SnsUserInfo getSnsUserInfoByUserId(int userId, int terminal);

    @Query(value = "select * from sns_user_info where open_id = ? and terminal = ? and deleted = 0 limit 1;", nativeQuery = true)
    SnsUserInfo getSnsUserInfoByOpenId(String openId, int terminal);

    @Query(value = "select * from sns_user_info where user_id = ? and nickname is not null and nickname <> '' and deleted = 0 order by update_time desc limit 1;", nativeQuery = true)
    SnsUserInfo getNickNameNotEmptyUserInfoByUserId(int userId);

    @Query(value = "select * from sns_user_info where user_id = ? and avatar is not null and avatar <> '' and deleted = 0 order by update_time desc limit 1;", nativeQuery = true)
    SnsUserInfo getAvatarNotEmptyUserInfoByUserId(int userId);

    @Query(value = "select * from sns_user_info where alipay_uid = ? and terminal = ? and deleted = 0 and user_id > 0 limit 1;", nativeQuery = true)
    SnsUserInfo getSnsUserInfoByAlipayUidAndTerminal(String alipayUid, int terminal);
}