package com.sikey.wa04.business.infrastructure.repository;

import com.sikey.wa04.business.infrastructure.dto.model.MapTrajectoryModel;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import org.springframework.data.domain.Limit;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.Instant;
import java.util.List;


/**
 * @Author: qin
 * @Date: 2025/3/11
 * @Description: 地图轨迹
 */
@Repository
public interface MapTrajectoryRepository extends JpaRepository<MapTrajectoryModel, String> {
    /**
     * 精确查询child_id + 时间范围
     * @param childId   小孩ID
     * @param start     开始时间
     * @param end       结束时间
     * @return          历史轨迹列表
     */
    List<MapTrajectoryModel> findByChildIdAndCreatedAtBetween(@Param("childId") String childId,
                                                              @Param("start") Instant start,
                                                              @Param("end") Instant end);

    List<MapTrajectoryModel> findByChildIdOrderByPositionTimeDesc(@Size(max = 36) @NotNull String childId, Sort sort, Limit limit);

    MapTrajectoryModel findByDeviceIdOrderByCreatedAtDesc(@NotNull Long deviceId, Sort sort, Limit limit);

    //  void deleteByTrajectoryIdIn(List<Long> trajectoryIds);
}
