package de.votian.services.repository;

import de.votian.services.entity.VehicleDisposition;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
import java.util.List;

public interface VehicleDispositionRepository extends JpaRepository<VehicleDisposition, Long> {

    Optional<VehicleDisposition> findByJobId(Long jobId);

    List<VehicleDisposition> findByJobIdIn(List<Long> jobIds);

    List<VehicleDisposition> findByCourierVehicleIdIn(List<Long> courierVehicleIds);

    @Query("SELECT vd FROM VehicleDisposition vd WHERE vd.courierVehicleId = :crvhId AND vd.jobId <> :excludeJobId")
    List<VehicleDisposition> findByCourierVehicleExcludingJob(@Param("crvhId") Long crvhId, @Param("excludeJobId") Long excludeJobId);

    void deleteByJobId(Long jobId);
}
