package com.agent.management.repository;

import com.agent.management.model.entity.WorkflowRun;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface WorkflowRunRepository extends JpaRepository<WorkflowRun, Long> {
    List<WorkflowRun> findByWorkflowIdOrderByStartedAtDesc(Long workflowId);
    List<WorkflowRun> findAllByOrderByStartedAtDesc();

    /**
     * v1.1：通过 runId 精确查询（runId 上有 unique 索引，避免 findAll + filter 全表扫描）。
     * 用于 GET /runs/{runId}/state、POST /runs/{runId}/resume 等断线重连场景。
     */
    Optional<WorkflowRun> findByRunId(String runId);
}

