package com.ttstd.dialer.db.contact;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import java.util.List;

@Dao
public interface ContactDao {
    // 基本查询：获取总行数
    @Query("SELECT COUNT(*) FROM contacts")
    int getTotalCount();

    // 查询：根据特定列的非空值计数
    @Query("SELECT COUNT(id) FROM contacts")
    int getCountById();

    @Insert
    long insert(ContactInfo contactInfo);

    @Update
    int update(ContactInfo contactInfo);

    @Delete
    int delete(ContactInfo contactInfo);

    @Query("DELETE FROM contacts WHERE id = :id")
    int deleteById(int id);

    @Query("DELETE FROM contacts")
    int deleteAll();

    @Query("SELECT * FROM contacts ORDER BY position ASC")
    List<ContactInfo> getAllContacts();

    @Query("SELECT * FROM contacts WHERE id = :id")
    ContactInfo getContactById(int id);

    @Query("SELECT * FROM contacts WHERE name LIKE :searchQuery OR phoneNumber LIKE :searchQuery")
    List<ContactInfo> searchContacts(String searchQuery);
}

