using OmsorgCore.Domain.Entities;

namespace OmsorgCore.Application.Services;

public enum DocumentUploadError
{
    None,
    InvalidCategory,
    FileTooLarge,
    ContentTypeNotAllowed
}

public record DocumentUploadResult(Document? Document, DocumentUploadError Error);

public enum DocumentUpdateError
{
    None,
    NotFound,
    InvalidCategory
}

public record DocumentUpdateResult(Document? Document, DocumentUpdateError Error);

public interface IDocumentService
{
    Task<DocumentUploadResult> UploadAsync(
        string entityType,
        Guid entityId,
        string category,
        string? description,
        string fileName,
        string contentType,
        long sizeBytes,
        Stream content,
        Guid uploadedByUserId,
        CancellationToken cancellationToken = default);

    Task<DocumentUpdateResult> UpdateAsync(
        Guid id,
        string category,
        string? description,
        string fileName,
        CancellationToken cancellationToken = default);

    Task<IReadOnlyList<Document>> GetByEntityAsync(string entityType, Guid entityId, CancellationToken cancellationToken = default);
    Task<Document?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
    Task<Stream?> OpenForDownloadAsync(Guid id, CancellationToken cancellationToken = default);
    Task<bool> DeleteAsync(Guid id, CancellationToken cancellationToken = default);
    Task<IReadOnlyList<Document>> GetDeletedAsync(string? search, CancellationToken cancellationToken = default);
    Task<bool> RestoreAsync(Guid id, CancellationToken cancellationToken = default);
}
