package com.example.todojava.data;

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 java.util.List;

@Dao
public interface TodoDao {

    @Query("SELECT * FROM todos ORDER BY created_at DESC")
    LiveData<List<Todo>> getAllTodos();

    @Query("SELECT * FROM todos WHERE completed = 0 ORDER BY created_at DESC")
    LiveData<List<Todo>> getActiveTodos();

    @Query("SELECT * FROM todos WHERE completed = 1 ORDER BY created_at DESC")
    LiveData<List<Todo>> getCompletedTodos();

    @Query("SELECT COUNT(*) FROM todos")
    LiveData<Integer> getAllCount();

    @Query("SELECT COUNT(*) FROM todos WHERE completed = 0")
    LiveData<Integer> getActiveCount();

    @Query("SELECT COUNT(*) FROM todos WHERE completed = 1")
    LiveData<Integer> getCompletedCount();

    @Insert
    void insert(Todo todo);

    @Update
    void update(Todo todo);

    @Delete
    void delete(Todo todo);

    @Query("SELECT * FROM todos WHERE id = :id")
    Todo getTodoById(long id);
}
