package com.prank.happypranksounds.data.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.happypranksounds.data.entity.HappyData;

import java.util.List;

@Dao
public interface HappyDataDao {

    @Insert
    void insertAll(List<HappyData> happyDataList);

    @Insert
    void insert(HappyData happyData);

    @Update
    void update(HappyData happyData);

    @Delete
    void delete(HappyData happyData);

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

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

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

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

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