package com.secspace.lib.common.function.database.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.secspace.lib.common.function.model.UseTime;

import java.util.List;

@Dao
public interface UseTimeDao {

    @Query("select * from use_time")
    List<UseTime> queryAll();

    @Query("select * from use_time where (start_time >= :startTime AND start_time <= :endTime AND end_time >= :endTime)" +
            " OR (end_time >= :startTime AND end_time <= :endTime AND start_time >= :startTime)" +
            " OR (start_time <= :startTime AND end_time >= :endTime)" +
            " OR (start_time >= :startTime AND end_time <= :endTime)")
    List<UseTime> queryByTime(long startTime, long endTime);

    @Query("select * from use_time where (app_package = :pkg) and ((start_time >= :startTime AND start_time <= :endTime AND end_time >= :endTime)" +
            " OR (end_time >= :startTime AND end_time <= :endTime AND start_time >= :startTime)" +
            " OR (start_time <= :startTime AND end_time >= :endTime)" +
            " OR (start_time >= :startTime AND end_time <= :endTime))")
    List<UseTime> queryByTimePkg(long startTime, long endTime, String pkg);

    @Query("select * from use_time where upload_time = 0")
    List<UseTime> queryNoupload();

    @Insert
    long insertUseTime(UseTime useTime);

    @Insert
    List<Long> insertUseTimes(List<UseTime> useTimes);

    @Update
    void updateUseTime(UseTime useTime);

    @Update
    void updateUseTimes(List<UseTime> useTimes);
}
