using ColaFlow.Modules.Mcp.Domain.Entities;
using ColaFlow.Modules.Mcp.Domain.ValueObjects;

namespace ColaFlow.Modules.Mcp.Domain.Repositories;

/// <summary>
/// Repository interface for TaskLock aggregate root
/// </summary>
public interface ITaskLockRepository
{
    /// <summary>
    /// Get a task lock by ID
    /// </summary>
    Task<TaskLock?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);

    /// <summary>
    /// Get all task locks for a tenant
    /// </summary>
    Task<IReadOnlyList<TaskLock>> GetByTenantAsync(
        Guid tenantId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Get active lock for a specific resource (if any)
    /// </summary>
    Task<TaskLock?> GetActiveLockForResourceAsync(
        Guid tenantId,
        string resourceType,
        Guid resourceId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Get all locks held by a specific holder
    /// </summary>
    Task<IReadOnlyList<TaskLock>> GetByLockHolderAsync(
        Guid tenantId,
        Guid lockHolderId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Get locks by status
    /// </summary>
    Task<IReadOnlyList<TaskLock>> GetByStatusAsync(
        Guid tenantId,
        TaskLockStatus status,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Get expired locks (still in Active status but past expiration time)
    /// </summary>
    Task<IReadOnlyList<TaskLock>> GetExpiredAsync(
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Check if a resource is currently locked
    /// </summary>
    Task<bool> IsResourceLockedAsync(
        Guid tenantId,
        string resourceType,
        Guid resourceId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Check if a resource is locked by a specific holder
    /// </summary>
    Task<bool> IsResourceLockedByAsync(
        Guid tenantId,
        string resourceType,
        Guid resourceId,
        Guid lockHolderId,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Add a new task lock
    /// </summary>
    Task AddAsync(TaskLock taskLock, CancellationToken cancellationToken = default);

    /// <summary>
    /// Update an existing task lock
    /// </summary>
    Task UpdateAsync(TaskLock taskLock, CancellationToken cancellationToken = default);

    /// <summary>
    /// Delete a task lock
    /// </summary>
    Task DeleteAsync(TaskLock taskLock, CancellationToken cancellationToken = default);

    /// <summary>
    /// Save changes to the database
    /// </summary>
    Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}
