package com.prank.funnypranksounds.data.local.dao;

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

import com.prank.funnypranksounds.data.local.entity.AudioData;

import java.util.List;

@Dao
public interface AudioDataDao {

    @Insert
    void insertAll(List<AudioData> audioDataList);

    @Insert
    void insert(AudioData audioData);

    @Update
    void update(AudioData audioData);

    @Delete
    void delete(AudioData audioData);

    @Query("SELECT * FROM AudioData WHERE id IN (SELECT MIN(id) FROM AudioData GROUP BY categoryName)")
    LiveData<List<AudioData>> getFirstCategory();

    @Query("SELECT * FROM AudioData WHERE categoryName = :name")
    LiveData<List<AudioData>> getCategory(String name);

    @Query("SELECT * FROM AudioData WHERE isFavorite = 1")
    LiveData<List<AudioData>> getFavorite();

    @Query("SELECT * FROM AudioData WHERE isExternal = 1")
    LiveData<List<AudioData>> getExternal();

    @Query("SELECT COUNT(*) FROM AudioData WHERE mp3Url = :uri")
    int getCount(String uri);
}
