package com.grigowashere.aismap.data.dao;

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

import com.grigowashere.aismap.data.entity.AISVesselEntity;

import java.util.List;

@Dao
public interface AISVesselDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void upsert(AISVesselEntity entity);

    @Update
    void update(AISVesselEntity entity);

    @Query("SELECT * FROM ais_vessels")
    List<AISVesselEntity> getAll();

    @Query("SELECT * FROM ais_vessels")
    LiveData<List<AISVesselEntity>> observeAll();

    @Query("SELECT * FROM ais_vessels WHERE mmsi = :mmsi LIMIT 1")
    AISVesselEntity getByMmsi(String mmsi);

    @Query("DELETE FROM ais_vessels WHERE lastUpdateEpochMs < :threshold")
    void deleteStale(long threshold);
}


