using System.ComponentModel;
using ClaudeDo.Data.Models;
using ClaudeDo.Data.Repositories;
using TaskStatus = ClaudeDo.Data.Models.TaskStatus;

namespace ClaudeDo.Ui.Services;

public interface IWorkerClient : INotifyPropertyChanged
{
    bool IsConnected { get; }

    event Action<string, string, DateTime>? TaskStartedEvent;
    event Action<string, string, string, DateTime>? TaskFinishedEvent;
    event Action<string>? TaskUpdatedEvent;
    /// <summary>Raised once when the SignalR connection is first established, and again on every reconnect.</summary>
    event Action? ConnectionRestoredEvent;
    event Action<string>? WorktreeUpdatedEvent;
    event Action<string>? ListUpdatedEvent;
    event Action<string, string>? TaskMessageEvent;

    event Action<string, string>? PlanningMergeStartedEvent;
    event Action<string, string>? PlanningSubtaskMergedEvent;
    event Action<string, string, IReadOnlyList<string>>? PlanningMergeConflictEvent;
    event Action<string>? PlanningMergeAbortedEvent;
    event Action<string>? PlanningCompletedEvent;

    Task WakeQueueAsync();
    Task RunNowAsync(string taskId);
    Task ContinueTaskAsync(string taskId, string followUpPrompt);
    Task ResetTaskAsync(string taskId);
    Task CancelTaskAsync(string taskId);
    Task<List<AgentInfo>> GetAgentsAsync();
    Task<ListConfigDto?> GetListConfigAsync(string listId);
    Task UpdateTaskAgentSettingsAsync(UpdateTaskAgentSettingsDto dto);
    Task SetTaskStatusAsync(string taskId, TaskStatus status);
    Task StartPlanningSessionAsync(string taskId, CancellationToken ct = default);
    Task OpenInteractiveTerminalAsync(string taskId, CancellationToken ct = default);
    Task ResumePlanningSessionAsync(string taskId, CancellationToken ct = default);
    Task<DiscardPlanningOutcome> DiscardPlanningSessionAsync(string taskId, bool dequeueQueuedChildren = false, CancellationToken ct = default);
    Task FinalizePlanningSessionAsync(string taskId, bool queueAgentTasks = true, CancellationToken ct = default);
    Task<int> GetPendingDraftCountAsync(string taskId, CancellationToken ct = default);
    Task<MergeTargetsDto?> GetMergeTargetsAsync(string taskId);
    Task<IReadOnlyList<SubtaskDiffDto>> GetPlanningAggregateAsync(string planningTaskId);
    Task<CombinedDiffResultDto?> BuildPlanningIntegrationBranchAsync(string planningTaskId, string targetBranch);
    Task MergeAllPlanningAsync(string planningTaskId, string targetBranch);
    Task ContinuePlanningMergeAsync(string planningTaskId);
    Task AbortPlanningMergeAsync(string planningTaskId);
    Task QueuePlanningSubtasksAsync(string parentTaskId, CancellationToken ct = default);
}
