namespace OmsorgCore.Application.Abstractions;

using OmsorgCore.Domain.Entities;

public interface IAssignmentRepository
{
    Task<Assignment?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<Assignment>> GetAllAsync(CancellationToken cancellationToken = default);
    Task<(IReadOnlyList<Assignment> Items, int TotalCount)> GetPagedAsync(
        Guid? orderId = null,
        Guid? employeeId = null,
        DateOnly? fromDate = null,
        DateOnly? toDate = null,
        int page = 1,
        int pageSize = 20,
        CancellationToken cancellationToken = default);

    Task<bool> HasOverlapAsync(
        Guid employeeId,
        DateOnly startDate,
        DateOnly endDate,
        Guid? excludeAssignmentId = null,
        CancellationToken cancellationToken = default);

    /// <summary>
    /// Zählt die Tage, an denen die Mitarbeiterin innerhalb von [weekStart, weekEnd] bereits
    /// eingeteilt ist (bestehende Zuweisungen, ohne excludeAssignmentId) - Basis für die
    /// Arbeitszeit-Näherung in FR-EM-3 (8h/Tag gegen Contract.WeeklyHours).
    /// </summary>
    Task<int> GetAssignedDayCountInWeekAsync(
        Guid employeeId,
        DateOnly weekStart,
        DateOnly weekEnd,
        Guid? excludeAssignmentId = null,
        CancellationToken cancellationToken = default);

    Task<int> CountForOrderAsync(Guid orderId, CancellationToken cancellationToken = default);

    Task AddAsync(Assignment assignment, CancellationToken cancellationToken = default);
    Task UpdateAsync(Assignment assignment, CancellationToken cancellationToken = default);
    Task<bool> SoftDeleteAsync(Guid id, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<Assignment>> GetDeletedAsync(string? search, CancellationToken cancellationToken = default);
    Task<bool> RestoreAsync(Guid id, CancellationToken cancellationToken = default);
    Task SaveChangesAsync(CancellationToken cancellationToken = default);
}
