package com.kolobochki.memory;

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

import java.util.List;

@Dao
public interface LevelRecordDao {
    @Insert
    void insert(LevelRecord record);

    @Update
    void update(LevelRecord record);

    @Query("SELECT * FROM level_records WHERE levelId = :levelId")
    LevelRecord getRecordForLevel(int levelId);

    @Query("SELECT * FROM level_records ORDER BY levelId ASC")
    List<LevelRecord> getAllRecords();

    @Query("DELETE FROM level_records")
    void deleteAllRecords();

    @Query("UPDATE level_records SET bestScore = :newScore, attemptsCount = attemptsCount + 1 WHERE levelId = :levelId AND :newScore > bestScore")
    void updateIfBetter(int levelId, int newScore);

}