package de.assecutor.votianlt.repository;

import de.assecutor.votianlt.model.task.BaseTask;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import java.util.List;

public interface TaskRepository extends MongoRepository<BaseTask, ObjectId> {
    List<BaseTask> findByStationIdOrderByTaskOrderAsc(ObjectId stationId);

    List<BaseTask> findByStationIdIn(List<ObjectId> stationIds);

    List<BaseTask> findByJobIdOrderByTaskOrderAsc(ObjectId jobId);

    @Query("{'job_id': {'$in': ?0}}")
    List<BaseTask> findByJobIdIn(List<ObjectId> jobIds);

    List<BaseTask> findByJobIdAndStationOrderOrderByTaskOrderAsc(ObjectId jobId, int stationOrder);

    /**
     * Count tasks by completion status
     */
    long countByCompleted(boolean completed);

    // Deprecated - use findByJobIdOrderByTaskOrderAsc instead
    @Deprecated
    default List<BaseTask> findByJobId(ObjectId jobId) {
        return findByJobIdOrderByTaskOrderAsc(jobId);
    }
}
