using Nexus.Api.Data;
using Nexus.Api.Models;

namespace Nexus.Api.Repositories;

public interface ITaskRepository
{
    Task<List<WorkTask>> GetAllAsync(CancellationToken ct = default);
    ValueTask<WorkTask?> GetByIdAsync(Guid id, CancellationToken ct = default);
    Task<List<WorkTask>> GetPendingApprovalAsync(CancellationToken ct = default);
    Task<WorkTask> AddAsync(WorkTask task, CancellationToken ct = default);
    Task<bool> TryResetStaleInProgressToBacklogAsync(Guid id, DateTimeOffset staleBefore, DateTimeOffset updatedAt, CancellationToken ct = default);
    Task UpdateAsync(WorkTask task, CancellationToken ct = default);
    Task DeleteAsync(WorkTask task, CancellationToken ct = default);
    Task<int> CountAsync(CancellationToken ct = default);
    Task<int> CountByStateAsync(string state, CancellationToken ct = default);
    Task<WorkTask?> GetLastBlockedAsync(CancellationToken ct = default);
    Task<TaskBoardQueryPage> GetBoardPageAsync(
        int doneLimit,
        DateTimeOffset? doneBeforeUpdatedAt,
        Guid? doneBeforeId,
        CancellationToken ct = default);
    Task<TaskBoardCardDto?> GetBoardCardAsync(
        Guid id,
        CancellationToken ct = default);
}

public sealed record TaskBoardQueryPage(
    IReadOnlyList<TaskBoardCardDto> ActiveTasks,
    IReadOnlyList<TaskBoardCardDto> DoneTasks,
    bool HasMoreDone,
    TaskBoardRevisionPoint? Revision);

public sealed record TaskBoardRevisionPoint(
    DateTimeOffset UpdatedAt,
    Guid Id);
