using Nexus.Api.Data;
using Nexus.Api.DTOs;
using Nexus.Api.Models;
namespace Nexus.Api.Services;
///
/// Structured backend bridge for agent/task commands.
/// Provides a clean, typed API for agents (Iris and sub-agents) to interact
/// with the task board, activity log, and delegation workflow.
///
/// This is the internal service layer — never exposed directly to the browser.
/// The GatewayBridgeController wraps this for agent-facing HTTP access.
///
public interface ITaskBridgeService
{
// ── Task CRUD (Agent-Commands) ──
///
/// Creates a new top-level task (parent or standalone).
/// Returns the created task DTO.
///
Task> CreateTaskAsync(
string title,
string? detail = null,
string? source = "iris",
string? priority = "Normal",
string? assignedTo = null,
Guid? projectId = null,
CancellationToken ct = default);
///
/// Creates a child task linked to an existing parent.
/// This is the primary delegation command: iris creates a child task,
/// assigns it to a sub-agent, and tracks it on the board.
///
Task> CreateChildTaskAsync(
Guid parentTaskId,
string title,
string? detail = null,
string? source = "iris",
string? priority = "Normal",
string? assignedTo = null,
string? expectedFrom = null,
CancellationToken ct = default);
///
/// Updates the status/state of a task.
/// Enforces CanChangeState rules (only iris/bao/nexus-system may change state).
///
Task> UpdateStatusAsync(
Guid taskId,
string state,
string? callerAgent = null,
CancellationToken ct = default);
///
/// Appends an activity entry to a task (comment, status note, agent note).
/// Used by agents to annotate their progress on the board.
///
Task> AppendActivityAsync(
Guid taskId,
string message,
string? type = "comment",
CancellationToken ct = default);
///
/// Handles a task handoff: sets ExpectedFrom to the target agent,
/// appends a handoff activity entry, and optionally updates assigned-to.
///
Task> HandoffAsync(
Guid taskId,
string targetAgent,
string? note = null,
CancellationToken ct = default);
// ── Query (Read) ──
///
/// Returns the full task board state (grouped by status column).
///
Task GetBoardAsync(CancellationToken ct = default);
///
/// Returns a single task by ID.
///
Task> GetTaskAsync(
Guid taskId,
CancellationToken ct = default);
///
/// Returns all child tasks for a given parent task.
///
Task> GetChildTasksAsync(
Guid parentTaskId,
CancellationToken ct = default);
///
/// Returns task activity history.
///
Task> GetTaskActivityAsync(
Guid taskId,
CancellationToken ct = default);
// ── Agent Workflow ──
///
/// Returns the agent-workflow overview: who is expected to respond,
/// stale tasks, workload distribution.
///
Task GetAgentOverviewAsync(
TimeSpan? staleThreshold = null,
CancellationToken ct = default);
}
///
/// Result pattern for task-bridge operations.
/// WorkTask? is null on NotFound; state is stored in the Outcome.
///
public sealed record TaskBridgeResult(
TaskBridgeOutcome Outcome,
T? Data = default,
string? Error = null
);
public enum TaskBridgeOutcome
{
Success,
NotFound,
InvalidState,
Unauthorized,
ValidationError
}