diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumedItemDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumedItemDto.cs
new file mode 100644
index 00000000..45a116a2
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumedItemDto.cs
@@ -0,0 +1,38 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for a media item of the consumption history, together with its aggregated consumption counts and display details.
+///
+/// The kind of the consumed media item.
+/// The Id of the consumed media item.
+/// The Id of the media library that contains the media item.
+/// Whether the media item still exists and can be accessed by the user. When , the title, collection title, creator name, and cover path are blank, while the identity and aggregation fields remain.
+/// The title of the media item, or an empty string when the item is not available.
+/// The title of the collection that contains the media item, or an empty string when there is none.
+/// The name of the creator of the media item, or an empty string when there is none.
+/// The path of the cover art of the media item, if available.
+/// The date and time when the media item was last consumed.
+/// The number of consumption sessions of the media item that count towards statistics.
+/// The number of consumption sessions of the media item that completed.
+/// The active duration consumed in the media item, over all of its sessions, in milliseconds.
+[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record ConsumedItemDto(
+ MediaKind MediaKind,
+ Guid MediaItemId,
+ Guid LibraryId,
+ bool IsAvailable,
+ string Title,
+ string CollectionTitle,
+ string CreatorName,
+ string? CoverPath,
+ DateTime LastConsumedOnUtc,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ long ConsumedDurationMilliseconds
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionRecordDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionRecordDto.cs
new file mode 100644
index 00000000..d488430e
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionRecordDto.cs
@@ -0,0 +1,39 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for a media consumption session.
+///
+/// The Id of the consumption record.
+/// The Id of the media library that contains the consumed media item.
+/// The Id of the consumed media item.
+/// The kind of media that was consumed.
+/// The state of the consumption session.
+/// The date and time when the session started.
+/// The date and time when the session last received activity.
+/// The date and time when the session completed or stopped, if it has ended.
+/// The active duration consumed by the session, in milliseconds.
+/// The last known position for the media item, if any.
+/// The latest reported progress fraction of the media item.
+/// The number of consecutive pages read in the session.
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
+public sealed record ConsumptionRecordDto(
+ Guid Id,
+ Guid LibraryId,
+ Guid MediaItemId,
+ MediaKind MediaKind,
+ ConsumptionStatus Status,
+ DateTime StartedOnUtc,
+ DateTime LastActivityOnUtc,
+ DateTime? EndedOnUtc,
+ long ConsumedDurationMilliseconds,
+ MediaPositionDto? LastPosition,
+ double LastProgressFraction,
+ int ConsecutivePagesRead
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionStatisticsDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionStatisticsDto.cs
new file mode 100644
index 00000000..b4b1b950
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/ConsumptionStatisticsDto.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for the consumption statistics of a user.
+///
+/// The Id of the user the statistics belong to.
+/// The total duration consumed over every recorded session, in milliseconds.
+/// The number of recorded sessions that count towards statistics.
+/// The number of recorded sessions that completed.
+/// The number of recorded sessions that stopped before they completed and count towards statistics.
+/// The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.
+/// The consumption statistics broken down by media kind.
+[DebuggerDisplay("UserId: {UserId}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record ConsumptionStatisticsDto(
+ Guid UserId,
+ long TotalConsumedDurationMilliseconds,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ int StoppedSessionCount,
+ double CompletionRate,
+ IReadOnlyList MediaKindSummaries
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/MediaKindConsumptionStatisticsDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/MediaKindConsumptionStatisticsDto.cs
new file mode 100644
index 00000000..cec9ecf0
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/MediaKindConsumptionStatisticsDto.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for the consumption statistics of a user for one kind of media.
+///
+/// The kind of media the statistics belong to.
+/// The total duration consumed over every recorded session of the media kind, in milliseconds.
+/// The number of recorded sessions of the media kind that count towards statistics.
+/// The number of recorded sessions of the media kind that completed.
+/// The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.
+/// The fraction of the counted sessions of the media kind that completed, between 0 and 1, or 0 when there is no counted session.
+[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record MediaKindConsumptionStatisticsDto(
+ MediaKind MediaKind,
+ long TotalConsumedDurationMilliseconds,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ int StoppedSessionCount,
+ double CompletionRate
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/MediaPositionDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/MediaPositionDto.cs
new file mode 100644
index 00000000..16c6214a
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/MediaPositionDto.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for a position reached in a media item during a consumption session.
+///
+/// The kind of representation used by the position.
+/// The position within the media item, in milliseconds, when the position is a time offset.
+/// The opaque locator within the media item, when the position is not a time offset.
+[DebuggerDisplay("Kind: {Kind}; TimeOffsetMilliseconds: {TimeOffsetMilliseconds}")]
+public sealed record MediaPositionDto(
+ MediaPositionKind Kind,
+ long? TimeOffsetMilliseconds,
+ string? Location
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/ResumePointDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/ResumePointDto.cs
new file mode 100644
index 00000000..08ae9047
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/ResumePointDto.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for the point at which a user can resume consuming a media item.
+///
+/// The Id of the resume point.
+/// The Id of the media library that contains the media item.
+/// The Id of the media item to resume.
+/// The kind of media that is resumed.
+/// The position at which the media item can be resumed.
+/// The progress fraction at which the media item can be resumed.
+/// The date and time when the media item was last consumed.
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
+public sealed record ResumePointDto(
+ Guid Id,
+ Guid LibraryId,
+ Guid MediaItemId,
+ MediaKind MediaKind,
+ MediaPositionDto LastPosition,
+ double LastProgressFraction,
+ DateTime LastConsumedOnUtc
+);
diff --git a/src/Lumina.Application/Common/DTO/MediaConsumption/TagConsumptionDto.cs b/src/Lumina.Application/Common/DTO/MediaConsumption/TagConsumptionDto.cs
new file mode 100644
index 00000000..c581c424
--- /dev/null
+++ b/src/Lumina.Application/Common/DTO/MediaConsumption/TagConsumptionDto.cs
@@ -0,0 +1,21 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DTO.MediaConsumption;
+
+///
+/// Data transfer object for the consumption statistics of a tag or genre, grouped across media kinds.
+///
+/// The lowercase name of the tag or genre.
+/// Whether the entry is a genre or a tag.
+/// The number of distinct media items that carry the term and were consumed.
+/// The active duration consumed in the media items that carry the term, in milliseconds.
+[DebuggerDisplay("TagKind: {TagKind}; Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
+public sealed record TagConsumptionDto(
+ string Name,
+ TagKind TagKind,
+ int ConsumedItemCount,
+ long ConsumedDurationMilliseconds
+);
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaConsumptionRecordEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaConsumptionRecordEntity.cs
new file mode 100644
index 00000000..f35c1123
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaConsumptionRecordEntity.cs
@@ -0,0 +1,118 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Common;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+
+///
+/// Repository entity for a media consumption session.
+///
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
+public class MediaConsumptionRecordEntity : IStorageEntity, IAuditableEntity
+{
+ ///
+ /// Gets the Id of the consumption record.
+ ///
+ public required Guid Id { get; init; }
+
+ ///
+ /// Gets the Id of the user that started the consumption session.
+ ///
+ public required Guid UserId { get; init; }
+
+ ///
+ /// Gets the Id of the media library that contains the consumed media item.
+ ///
+ public required Guid LibraryId { get; init; }
+
+ ///
+ /// Gets the kind of media that was consumed.
+ ///
+ public required MediaKind MediaKind { get; init; }
+
+ ///
+ /// Gets the Id of the consumed media item.
+ ///
+ public required Guid MediaItemId { get; init; }
+
+ ///
+ /// Gets or sets the state of the consumption session.
+ ///
+ public ConsumptionStatus Status { get; set; }
+
+ ///
+ /// Gets the date and time when the consumption session started.
+ ///
+ public required DateTime StartedOnUtc { get; init; }
+
+ ///
+ /// Gets or sets the date and time when the consumption session last received activity.
+ ///
+ public DateTime LastActivityOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the date and time when the consumption session completed or stopped, if it has ended.
+ ///
+ public DateTime? EndedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the active duration consumed by the session, in milliseconds. It is stored as a whole number of milliseconds so that the
+ /// stored value is independent of the persistence medium's support for time values.
+ ///
+ public long ConsumedDurationMilliseconds { get; set; }
+
+ ///
+ /// Gets or sets the kind of representation used by the last known position, if the session has a known position.
+ ///
+ public MediaPositionKind? LastPositionKind { get; set; }
+
+ ///
+ /// Gets or sets the last known position within the media item, in milliseconds, when the position is a time offset.
+ ///
+ public long? LastPositionTimeOffsetMilliseconds { get; set; }
+
+ ///
+ /// Gets or sets the last known opaque locator within the media item, when the position is not a time offset.
+ ///
+ public string? LastPositionLocation { get; set; }
+
+ ///
+ /// Gets or sets the latest reported progress fraction of the media item.
+ ///
+ public double LastProgressFraction { get; set; }
+
+ ///
+ /// Gets or sets the number of consecutive pages read in the consumption session.
+ ///
+ public int ConsecutivePagesRead { get; set; }
+
+ ///
+ /// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the record before
+ /// another report changed it can never overwrite the newer state.
+ ///
+ public long Version { get; set; }
+
+ ///
+ /// Gets or sets the time and date when the entity was added.
+ ///
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
+
+ ///
+ /// Gets or sets the optional time and date when the entity was updated.
+ ///
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
+}
diff --git a/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaResumePointEntity.cs b/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaResumePointEntity.cs
new file mode 100644
index 00000000..3ac22e66
--- /dev/null
+++ b/src/Lumina.Application/Common/DataAccess/Entities/MediaConsumption/MediaResumePointEntity.cs
@@ -0,0 +1,92 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.Common;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+
+///
+/// Repository entity for the point at which a user can resume consuming a media item.
+///
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
+public class MediaResumePointEntity : IStorageEntity, IAuditableEntity
+{
+ ///
+ /// Gets the Id of the resume point.
+ ///
+ public required Guid Id { get; init; }
+
+ ///
+ /// Gets the Id of the user that owns the resume point.
+ ///
+ public required Guid UserId { get; init; }
+
+ ///
+ /// Gets the Id of the media library that contains the media item.
+ ///
+ public required Guid LibraryId { get; init; }
+
+ ///
+ /// Gets the kind of media that is resumed.
+ ///
+ public required MediaKind MediaKind { get; init; }
+
+ ///
+ /// Gets the Id of the media item to resume.
+ ///
+ public required Guid MediaItemId { get; init; }
+
+ ///
+ /// Gets the kind of representation used by the position at which the media item can be resumed.
+ ///
+ public required MediaPositionKind LastPositionKind { get; init; }
+
+ ///
+ /// Gets or sets the position within the media item, in milliseconds, when the position is a time offset.
+ ///
+ public long? LastPositionTimeOffsetMilliseconds { get; set; }
+
+ ///
+ /// Gets or sets the opaque locator within the media item, when the position is not a time offset.
+ ///
+ public string? LastPositionLocation { get; set; }
+
+ ///
+ /// Gets or sets the progress fraction at which the media item can be resumed.
+ ///
+ public double LastProgressFraction { get; set; }
+
+ ///
+ /// Gets or sets the date and time when the media item was last consumed.
+ ///
+ public DateTime LastConsumedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the version of the stored row. It is used as an optimistic concurrency token, so that a report that read the resume point before
+ /// another report changed it can never overwrite the newer state.
+ ///
+ public long Version { get; set; }
+
+ ///
+ /// Gets or sets the time and date when the entity was added.
+ ///
+ public required DateTime CreatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the Id of the user that created the entity.
+ ///
+ public required Guid CreatedBy { get; set; }
+
+ ///
+ /// Gets or sets the optional time and date when the entity was updated.
+ ///
+ public DateTime? UpdatedOnUtc { get; set; }
+
+ ///
+ /// Gets or sets the optional Id of the user that updated the entity.
+ ///
+ public required Guid? UpdatedBy { get; set; }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumedItemDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumedItemDtoMapping.cs
new file mode 100644
index 00000000..4e9c03c7
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumedItemDtoMapping.cs
@@ -0,0 +1,56 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Application.Common.DTO.Pagination;
+using Lumina.Contracts.Responses.Common;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+using System.Linq;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class ConsumedItemDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static ConsumedItemResponse ToResponse(this ConsumedItemDto data)
+ {
+ return new ConsumedItemResponse(
+ data.MediaKind,
+ data.MediaItemId,
+ data.LibraryId,
+ data.IsAvailable,
+ data.Title,
+ data.CollectionTitle,
+ data.CreatorName,
+ data.CoverPath,
+ DateTime.SpecifyKind(data.LastConsumedOnUtc, DateTimeKind.Utc),
+ data.CountedSessionCount,
+ data.CompletedSessionCount,
+ TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds
+ );
+ }
+
+ ///
+ /// Converts to a paginated collection of .
+ ///
+ /// The paginated data transfer objects to be converted.
+ /// The converted paginated responses.
+ public static PaginatedResponse ToResponses(this PaginatedResultDto data)
+ {
+ return new PaginatedResponse
+ {
+ Data = [.. data.Data.Select(item => item.ToResponse())],
+ CurrentPage = data.CurrentPage,
+ PerPage = data.PerPage,
+ Count = data.Count,
+ NumberOfPages = data.NumberOfPages
+ };
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionRecordDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionRecordDtoMapping.cs
new file mode 100644
index 00000000..3d90a200
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionRecordDtoMapping.cs
@@ -0,0 +1,37 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . This mapping is the record response builder for repository-driven
+/// single-record reads.
+///
+public static class ConsumptionRecordDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static ConsumptionRecordResponse ToResponse(this ConsumptionRecordDto data)
+ {
+ return new ConsumptionRecordResponse(
+ data.Id,
+ data.LibraryId,
+ data.MediaItemId,
+ data.MediaKind,
+ data.Status,
+ DateTime.SpecifyKind(data.StartedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(data.LastActivityOnUtc, DateTimeKind.Utc),
+ data.EndedOnUtc.HasValue ? DateTime.SpecifyKind(data.EndedOnUtc.Value, DateTimeKind.Utc) : null,
+ TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds,
+ data.LastPosition?.ToResponse(),
+ data.LastProgressFraction,
+ data.ConsecutivePagesRead
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionStatisticsDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionStatisticsDtoMapping.cs
new file mode 100644
index 00000000..17b9db89
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/ConsumptionStatisticsDtoMapping.cs
@@ -0,0 +1,32 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+using System.Linq;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class ConsumptionStatisticsDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static ConsumptionSummaryResponse ToResponse(this ConsumptionStatisticsDto data)
+ {
+ return new ConsumptionSummaryResponse(
+ data.UserId,
+ TimeSpan.FromMilliseconds(data.TotalConsumedDurationMilliseconds).TotalSeconds,
+ data.CountedSessionCount,
+ data.CompletedSessionCount,
+ data.StoppedSessionCount,
+ data.CompletionRate,
+ [.. data.MediaKindSummaries.Select(mediaKindSummary => mediaKindSummary.ToResponse())]
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordEntityMapping.cs
new file mode 100644
index 00000000..03f2e8df
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordEntityMapping.cs
@@ -0,0 +1,108 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate.ValueObjects;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class MediaConsumptionRecordEntityMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ ///
+ /// An containing either a successfully converted , or an error message.
+ ///
+ public static Result ToDomainEntity(this MediaConsumptionRecordEntity repositoryEntity)
+ {
+ Optional endedOnUtc = repositoryEntity.EndedOnUtc.HasValue
+ ? Optional.Some(DateTime.SpecifyKind(repositoryEntity.EndedOnUtc.Value, DateTimeKind.Utc))
+ : Optional.None();
+
+ Optional lastPosition = Optional.None();
+ if (repositoryEntity.LastPositionKind.HasValue)
+ {
+ MediaPositionKind positionKind = repositoryEntity.LastPositionKind.Value;
+ if (positionKind == MediaPositionKind.TimeOffset)
+ {
+ if (!repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue ||
+ repositoryEntity.LastPositionTimeOffsetMilliseconds.Value < 0 ||
+ repositoryEntity.LastPositionLocation is not null)
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+ lastPosition = Optional.Some(
+ MediaPosition.CreateTimeOffset(TimeSpan.FromMilliseconds(repositoryEntity.LastPositionTimeOffsetMilliseconds.Value)));
+ }
+ else if (positionKind == MediaPositionKind.Location)
+ {
+ if (string.IsNullOrWhiteSpace(repositoryEntity.LastPositionLocation) ||
+ repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue)
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+ lastPosition = Optional.Some(MediaPosition.CreateLocation(repositoryEntity.LastPositionLocation));
+ }
+ else
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+ }
+
+ return MediaConsumptionRecord.Reconstitute(
+ MediaConsumptionRecordId.Create(repositoryEntity.Id),
+ UserId.Create(repositoryEntity.UserId),
+ LibraryId.Create(repositoryEntity.LibraryId),
+ MediaItemId.Create(repositoryEntity.MediaItemId),
+ repositoryEntity.MediaKind,
+ repositoryEntity.Status,
+ DateTime.SpecifyKind(repositoryEntity.StartedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(repositoryEntity.LastActivityOnUtc, DateTimeKind.Utc),
+ endedOnUtc,
+ TimeSpan.FromMilliseconds(repositoryEntity.ConsumedDurationMilliseconds),
+ lastPosition,
+ repositoryEntity.LastProgressFraction,
+ repositoryEntity.ConsecutivePagesRead
+ );
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ /// The converted data transfer object.
+ public static ConsumptionRecordDto ToDto(this MediaConsumptionRecordEntity repositoryEntity)
+ {
+ MediaPositionDto? lastPosition = null;
+ if (repositoryEntity.LastPositionKind.HasValue)
+ {
+ lastPosition = new MediaPositionDto(
+ repositoryEntity.LastPositionKind.Value,
+ repositoryEntity.LastPositionTimeOffsetMilliseconds,
+ repositoryEntity.LastPositionLocation);
+ }
+
+ return new ConsumptionRecordDto(
+ repositoryEntity.Id,
+ repositoryEntity.LibraryId,
+ repositoryEntity.MediaItemId,
+ repositoryEntity.MediaKind,
+ repositoryEntity.Status,
+ DateTime.SpecifyKind(repositoryEntity.StartedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(repositoryEntity.LastActivityOnUtc, DateTimeKind.Utc),
+ repositoryEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(repositoryEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
+ repositoryEntity.ConsumedDurationMilliseconds,
+ lastPosition,
+ repositoryEntity.LastProgressFraction,
+ repositoryEntity.ConsecutivePagesRead
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordMapping.cs
new file mode 100644
index 00000000..0dd3e24e
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaConsumptionRecordMapping.cs
@@ -0,0 +1,101 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaConsumptionRecordAggregate;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . The record is mapped directly to its repository entity and to its response.
+/// Repository-driven single-record reads map the entity to its DTO and then to the response.
+///
+public static class MediaConsumptionRecordMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted repository entity.
+ public static MediaConsumptionRecordEntity ToRepositoryEntity(this MediaConsumptionRecord domainEntity)
+ {
+ return new MediaConsumptionRecordEntity
+ {
+ Id = domainEntity.Id.Value,
+ UserId = domainEntity.UserId.Value,
+ LibraryId = domainEntity.LibraryId.Value,
+ MediaKind = domainEntity.MediaKind,
+ MediaItemId = domainEntity.MediaItemId.Value,
+ Status = domainEntity.Status,
+ StartedOnUtc = domainEntity.StartedOnUtc,
+ LastActivityOnUtc = domainEntity.LastActivityOnUtc,
+ EndedOnUtc = domainEntity.EndedOnUtc.HasValue ? domainEntity.EndedOnUtc.Value : null,
+ // Stored time is truncated to whole milliseconds instead of rounded, so a retried report of the same fractional second maps to
+ // the same stored value and is not rejected as a decrease by the domain.
+ ConsumedDurationMilliseconds = (long)domainEntity.ConsumedDuration.TotalMilliseconds,
+ LastPositionKind = domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.Kind : null,
+ LastPositionTimeOffsetMilliseconds = domainEntity.LastPosition.HasValue && domainEntity.LastPosition.Value.TimeOffset.HasValue
+ ? (long)domainEntity.LastPosition.Value.TimeOffset.Value.TotalMilliseconds
+ : null,
+ LastPositionLocation = domainEntity.LastPosition.HasValue && domainEntity.LastPosition.Value.Location.HasValue
+ ? domainEntity.LastPosition.Value.Location.Value
+ : null,
+ LastProgressFraction = domainEntity.LastProgressFraction,
+ ConsecutivePagesRead = domainEntity.ConsecutivePagesRead,
+ Version = 1,
+ CreatedOnUtc = domainEntity.CreatedOnUtc,
+ CreatedBy = Guid.Empty,
+ // The audit columns are owned by the auditing interceptor, so they are never mapped here.
+ UpdatedOnUtc = null,
+ UpdatedBy = null
+ };
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted data transfer object.
+ public static ConsumptionRecordDto ToDto(this MediaConsumptionRecord domainEntity)
+ {
+ return new ConsumptionRecordDto(
+ domainEntity.Id.Value,
+ domainEntity.LibraryId.Value,
+ domainEntity.MediaItemId.Value,
+ domainEntity.MediaKind,
+ domainEntity.Status,
+ DateTime.SpecifyKind(domainEntity.StartedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(domainEntity.LastActivityOnUtc, DateTimeKind.Utc),
+ domainEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(domainEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
+ (long)domainEntity.ConsumedDuration.TotalMilliseconds,
+ domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.ToDto() : null,
+ domainEntity.LastProgressFraction,
+ domainEntity.ConsecutivePagesRead
+ );
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted response.
+ public static ConsumptionRecordResponse ToResponse(this MediaConsumptionRecord domainEntity)
+ {
+ return new ConsumptionRecordResponse(
+ domainEntity.Id.Value,
+ domainEntity.LibraryId.Value,
+ domainEntity.MediaItemId.Value,
+ domainEntity.MediaKind,
+ domainEntity.Status,
+ DateTime.SpecifyKind(domainEntity.StartedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(domainEntity.LastActivityOnUtc, DateTimeKind.Utc),
+ domainEntity.EndedOnUtc.HasValue ? DateTime.SpecifyKind(domainEntity.EndedOnUtc.Value, DateTimeKind.Utc) : null,
+ domainEntity.ConsumedDuration.TotalSeconds,
+ domainEntity.LastPosition.HasValue ? domainEntity.LastPosition.Value.ToResponse() : null,
+ domainEntity.LastProgressFraction,
+ domainEntity.ConsecutivePagesRead
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaKindConsumptionStatisticsDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaKindConsumptionStatisticsDtoMapping.cs
new file mode 100644
index 00000000..1c2dddd8
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaKindConsumptionStatisticsDtoMapping.cs
@@ -0,0 +1,30 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class MediaKindConsumptionStatisticsDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static MediaKindConsumptionSummaryResponse ToResponse(this MediaKindConsumptionStatisticsDto data)
+ {
+ return new MediaKindConsumptionSummaryResponse(
+ data.MediaKind,
+ TimeSpan.FromMilliseconds(data.TotalConsumedDurationMilliseconds).TotalSeconds,
+ data.CountedSessionCount,
+ data.CompletedSessionCount,
+ data.StoppedSessionCount,
+ data.CompletionRate
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionDtoMapping.cs
new file mode 100644
index 00000000..18d8f346
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionDtoMapping.cs
@@ -0,0 +1,27 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . This mapping is the position response builder for repository-driven reads.
+///
+public static class MediaPositionDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static MediaPositionResponse ToResponse(this MediaPositionDto data)
+ {
+ return new MediaPositionResponse(
+ data.Kind,
+ data.TimeOffsetMilliseconds.HasValue ? TimeSpan.FromMilliseconds(data.TimeOffsetMilliseconds.Value).TotalSeconds : null,
+ data.Location
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionMapping.cs
new file mode 100644
index 00000000..7ced73f5
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaPositionMapping.cs
@@ -0,0 +1,41 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . The position is mapped directly to its DTO and to its response.
+///
+public static class MediaPositionMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The domain value object to be converted.
+ /// The converted data transfer object.
+ public static MediaPositionDto ToDto(this MediaPosition domainValueObject)
+ {
+ return new MediaPositionDto(
+ domainValueObject.Kind,
+ domainValueObject.TimeOffset.HasValue ? (long)domainValueObject.TimeOffset.Value.TotalMilliseconds : null,
+ domainValueObject.Location.HasValue ? domainValueObject.Location.Value : null
+ );
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The domain value object to be converted.
+ /// The converted response.
+ public static MediaPositionResponse ToResponse(this MediaPosition domainValueObject)
+ {
+ return new MediaPositionResponse(
+ domainValueObject.Kind,
+ domainValueObject.TimeOffset.HasValue ? domainValueObject.TimeOffset.Value.TotalSeconds : null,
+ domainValueObject.Location.HasValue ? domainValueObject.Location.Value : null
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointEntityMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointEntityMapping.cs
new file mode 100644
index 00000000..4442e3a3
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointEntityMapping.cs
@@ -0,0 +1,87 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Domain.Common.Primitives;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.Common.ValueObjects;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.MediaLibraryBoundedContext.MediaItemAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.ExternalIdentifiers.UserManagementBoundedContext.UserAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate.ValueObjects;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System;
+using DomainErrors = Lumina.Domain.Common.Errors.Errors;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class MediaResumePointEntityMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ ///
+ /// An containing either a successfully converted , or an error message.
+ ///
+ public static Result ToDomainEntity(this MediaResumePointEntity repositoryEntity)
+ {
+ MediaPosition lastPosition;
+ if (repositoryEntity.LastPositionKind == MediaPositionKind.TimeOffset)
+ {
+ if (!repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue ||
+ repositoryEntity.LastPositionTimeOffsetMilliseconds.Value < 0 ||
+ repositoryEntity.LastPositionLocation is not null)
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+ lastPosition = MediaPosition.CreateTimeOffset(TimeSpan.FromMilliseconds(repositoryEntity.LastPositionTimeOffsetMilliseconds.Value));
+ }
+ else if (repositoryEntity.LastPositionKind == MediaPositionKind.Location)
+ {
+ if (string.IsNullOrWhiteSpace(repositoryEntity.LastPositionLocation) ||
+ repositoryEntity.LastPositionTimeOffsetMilliseconds.HasValue)
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+ lastPosition = MediaPosition.CreateLocation(repositoryEntity.LastPositionLocation);
+ }
+ else
+ return DomainErrors.MediaConsumption.InvalidMediaPosition;
+
+ return MediaResumePoint.Reconstitute(
+ MediaResumePointId.Create(repositoryEntity.Id),
+ UserId.Create(repositoryEntity.UserId),
+ LibraryId.Create(repositoryEntity.LibraryId),
+ MediaItemId.Create(repositoryEntity.MediaItemId),
+ repositoryEntity.MediaKind,
+ lastPosition,
+ repositoryEntity.LastProgressFraction,
+ DateTime.SpecifyKind(repositoryEntity.LastConsumedOnUtc, DateTimeKind.Utc),
+ DateTime.SpecifyKind(repositoryEntity.CreatedOnUtc, DateTimeKind.Utc),
+ repositoryEntity.UpdatedOnUtc.HasValue
+ ? Optional.Some(DateTime.SpecifyKind(repositoryEntity.UpdatedOnUtc.Value, DateTimeKind.Utc))
+ : Optional.None()
+ );
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The repository entity to be converted.
+ /// The converted data transfer object.
+ public static ResumePointDto ToDto(this MediaResumePointEntity repositoryEntity)
+ {
+ return new ResumePointDto(
+ repositoryEntity.Id,
+ repositoryEntity.LibraryId,
+ repositoryEntity.MediaItemId,
+ repositoryEntity.MediaKind,
+ new MediaPositionDto(
+ repositoryEntity.LastPositionKind,
+ repositoryEntity.LastPositionTimeOffsetMilliseconds,
+ repositoryEntity.LastPositionLocation),
+ repositoryEntity.LastProgressFraction,
+ DateTime.SpecifyKind(repositoryEntity.LastConsumedOnUtc, DateTimeKind.Utc)
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointMapping.cs
new file mode 100644
index 00000000..7ce6aefd
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/MediaResumePointMapping.cs
@@ -0,0 +1,84 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DataAccess.Entities.MediaConsumption;
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using Lumina.Domain.Core.BoundedContexts.MediaConsumptionBoundedContext.MediaResumePointAggregate;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . The resume point is mapped directly to its repository entity and to its response.
+/// Repository-driven single-record reads map the entity to its DTO and then to the response.
+///
+public static class MediaResumePointMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted repository entity.
+ public static MediaResumePointEntity ToRepositoryEntity(this MediaResumePoint domainEntity)
+ {
+ return new MediaResumePointEntity
+ {
+ Id = domainEntity.Id.Value,
+ UserId = domainEntity.UserId.Value,
+ LibraryId = domainEntity.LibraryId.Value,
+ MediaKind = domainEntity.MediaKind,
+ MediaItemId = domainEntity.MediaItemId.Value,
+ LastPositionKind = domainEntity.LastPosition.Kind,
+ LastPositionTimeOffsetMilliseconds = domainEntity.LastPosition.TimeOffset.HasValue
+ ? (long)domainEntity.LastPosition.TimeOffset.Value.TotalMilliseconds
+ : null,
+ LastPositionLocation = domainEntity.LastPosition.Location.HasValue
+ ? domainEntity.LastPosition.Location.Value
+ : null,
+ LastProgressFraction = domainEntity.LastProgressFraction,
+ LastConsumedOnUtc = domainEntity.LastConsumedOnUtc,
+ Version = 1,
+ CreatedOnUtc = domainEntity.CreatedOnUtc,
+ CreatedBy = Guid.Empty,
+ // The audit columns are owned by the auditing interceptor, so they are never mapped here.
+ UpdatedOnUtc = null,
+ UpdatedBy = null
+ };
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted data transfer object.
+ public static ResumePointDto ToDto(this MediaResumePoint domainEntity)
+ {
+ return new ResumePointDto(
+ domainEntity.Id.Value,
+ domainEntity.LibraryId.Value,
+ domainEntity.MediaItemId.Value,
+ domainEntity.MediaKind,
+ domainEntity.LastPosition.ToDto(),
+ domainEntity.LastProgressFraction,
+ DateTime.SpecifyKind(domainEntity.LastConsumedOnUtc, DateTimeKind.Utc)
+ );
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The domain entity to be converted.
+ /// The converted response.
+ public static ResumePointResponse ToResponse(this MediaResumePoint domainEntity)
+ {
+ return new ResumePointResponse(
+ domainEntity.Id.Value,
+ domainEntity.LibraryId.Value,
+ domainEntity.MediaItemId.Value,
+ domainEntity.MediaKind,
+ domainEntity.LastPosition.ToResponse(),
+ domainEntity.LastProgressFraction,
+ DateTime.SpecifyKind(domainEntity.LastConsumedOnUtc, DateTimeKind.Utc)
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/ResumePointDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/ResumePointDtoMapping.cs
new file mode 100644
index 00000000..52fb7b08
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/ResumePointDtoMapping.cs
@@ -0,0 +1,32 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting . This mapping is the resume point response builder for repository-driven
+/// single-record reads.
+///
+public static class ResumePointDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static ResumePointResponse ToResponse(this ResumePointDto data)
+ {
+ return new ResumePointResponse(
+ data.Id,
+ data.LibraryId,
+ data.MediaItemId,
+ data.MediaKind,
+ data.LastPosition.ToResponse(),
+ data.LastProgressFraction,
+ DateTime.SpecifyKind(data.LastConsumedOnUtc, DateTimeKind.Utc)
+ );
+ }
+}
diff --git a/src/Lumina.Application/Common/Mapping/MediaConsumption/TagConsumptionDtoMapping.cs b/src/Lumina.Application/Common/Mapping/MediaConsumption/TagConsumptionDtoMapping.cs
new file mode 100644
index 00000000..0e92c932
--- /dev/null
+++ b/src/Lumina.Application/Common/Mapping/MediaConsumption/TagConsumptionDtoMapping.cs
@@ -0,0 +1,40 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Application.Common.DTO.MediaConsumption;
+using Lumina.Contracts.Responses.MediaConsumption;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+#endregion
+
+namespace Lumina.Application.Common.Mapping.MediaConsumption;
+
+///
+/// Extension methods for converting .
+///
+public static class TagConsumptionDtoMapping
+{
+ ///
+ /// Converts to .
+ ///
+ /// The data transfer object to be converted.
+ /// The converted response.
+ public static TagConsumptionResponse ToResponse(this TagConsumptionDto data)
+ {
+ return new TagConsumptionResponse(
+ data.Name,
+ data.TagKind,
+ data.ConsumedItemCount,
+ TimeSpan.FromMilliseconds(data.ConsumedDurationMilliseconds).TotalSeconds
+ );
+ }
+
+ ///
+ /// Converts to a collection of .
+ ///
+ /// The data transfer objects to be converted.
+ /// The converted responses.
+ public static IReadOnlyList ToResponses(this IReadOnlyList data)
+ {
+ return [.. data.Select(item => item.ToResponse())];
+ }
+}
diff --git a/src/Lumina.Contracts/Requests/MediaConsumption/CompleteConsumptionRequest.cs b/src/Lumina.Contracts/Requests/MediaConsumption/CompleteConsumptionRequest.cs
new file mode 100644
index 00000000..79b76e5a
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaConsumption/CompleteConsumptionRequest.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaConsumption;
+
+///
+/// Represents a request to report that a media consumption session completed.
+///
+/// The final position reported for the media item, if the client knows it. Optional.
+/// The fraction of the media item that the client reached, between 0 and 1. Required.
+/// The active duration consumed by the session, in seconds. Required.
+[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
+public sealed record CompleteConsumptionRequest(
+ MediaPositionRequest? Position,
+ double ProgressFraction,
+ double ConsumedDurationInSeconds
+);
diff --git a/src/Lumina.Contracts/Requests/MediaConsumption/MediaPositionRequest.cs b/src/Lumina.Contracts/Requests/MediaConsumption/MediaPositionRequest.cs
new file mode 100644
index 00000000..5ed05fb0
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaConsumption/MediaPositionRequest.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaConsumption;
+
+///
+/// Represents a request to report a position in a media consumption session.
+///
+/// The kind of the position. Required.
+/// The position within the media item, in seconds, when the position is a time offset. Optional.
+/// The opaque locator within the media item, when the position is not a time offset. Optional.
+[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
+public sealed record MediaPositionRequest(
+ string? Kind,
+ double? TimeOffsetSeconds,
+ string? Location
+);
diff --git a/src/Lumina.Contracts/Requests/MediaConsumption/ReportConsumptionProgressRequest.cs b/src/Lumina.Contracts/Requests/MediaConsumption/ReportConsumptionProgressRequest.cs
new file mode 100644
index 00000000..53a6cb56
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaConsumption/ReportConsumptionProgressRequest.cs
@@ -0,0 +1,20 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaConsumption;
+
+///
+/// Represents a request to report the progress of a media consumption session.
+///
+/// The last position reported for the media item, if the client knows it. Optional.
+/// The fraction of the media item that the client reached, between 0 and 1. Required.
+/// The active duration consumed by the session, in seconds. Required.
+/// The number of consecutive pages read in the current session, used by page based media such as books and ignored for other kinds. Defaults to 0. Optional.
+[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}; ConsecutivePagesRead: {ConsecutivePagesRead}")]
+public sealed record ReportConsumptionProgressRequest(
+ MediaPositionRequest? Position,
+ double ProgressFraction,
+ double ConsumedDurationInSeconds,
+ int ConsecutivePagesRead = 0
+);
diff --git a/src/Lumina.Contracts/Requests/MediaConsumption/StopConsumptionRequest.cs b/src/Lumina.Contracts/Requests/MediaConsumption/StopConsumptionRequest.cs
new file mode 100644
index 00000000..9295cc65
--- /dev/null
+++ b/src/Lumina.Contracts/Requests/MediaConsumption/StopConsumptionRequest.cs
@@ -0,0 +1,18 @@
+#region ========================================================================= USING =====================================================================================
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Requests.MediaConsumption;
+
+///
+/// Represents a request to report that a media consumption session stopped.
+///
+/// The final position reported for the media item, if the client knows it. Optional.
+/// The fraction of the media item that the client reached, between 0 and 1. Required.
+/// The active duration consumed by the session, in seconds. Required.
+[DebuggerDisplay("ProgressFraction: {ProgressFraction}; ConsumedDurationInSeconds: {ConsumedDurationInSeconds}")]
+public sealed record StopConsumptionRequest(
+ MediaPositionRequest? Position,
+ double ProgressFraction,
+ double ConsumedDurationInSeconds
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/ConsumedItemResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumedItemResponse.cs
new file mode 100644
index 00000000..d6b9f2f0
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumedItemResponse.cs
@@ -0,0 +1,38 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents a media item of the consumption history, together with its aggregated consumption counts and display details.
+///
+/// The kind of the consumed media item.
+/// The Id of the consumed media item.
+/// The Id of the media library that contains the media item.
+/// Whether the media item still exists and can be accessed by the user. When , the title, collection title, creator name, and cover path are blank, while the identity and aggregation fields remain.
+/// The title of the media item, or an empty string when the item is not available.
+/// The title of the collection that contains the media item, or an empty string when there is none.
+/// The name of the creator of the media item, or an empty string when there is none.
+/// The path of the cover art of the media item, if available.
+/// The date and time when the media item was last consumed.
+/// The number of consumption sessions of the media item that count towards statistics.
+/// The number of consumption sessions of the media item that completed.
+/// The active duration consumed in the media item, over all of its sessions, in seconds.
+[DebuggerDisplay("MediaKind: {MediaKind}; MediaItemId: {MediaItemId}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record ConsumedItemResponse(
+ MediaKind MediaKind,
+ Guid MediaItemId,
+ Guid LibraryId,
+ bool IsAvailable,
+ string Title,
+ string CollectionTitle,
+ string CreatorName,
+ string? CoverPath,
+ DateTime LastConsumedOnUtc,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ double ConsumedDurationInSeconds
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionRecordResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionRecordResponse.cs
new file mode 100644
index 00000000..96f222b4
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionRecordResponse.cs
@@ -0,0 +1,39 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents a media consumption session.
+///
+/// The Id of the consumption record.
+/// The Id of the media library that contains the consumed media item.
+/// The Id of the consumed media item.
+/// The kind of media that was consumed.
+/// The state of the consumption session.
+/// The date and time when the session started.
+/// The date and time when the session last received activity.
+/// The date and time when the session completed or stopped, if it has ended.
+/// The active duration consumed by the session, in seconds.
+/// The last known position for the media item, if any.
+/// The latest reported progress fraction of the media item.
+/// The number of consecutive pages read in the session.
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; Status: {Status}")]
+public sealed record ConsumptionRecordResponse(
+ Guid Id,
+ Guid LibraryId,
+ Guid MediaItemId,
+ MediaKind MediaKind,
+ ConsumptionStatus Status,
+ DateTime StartedOnUtc,
+ DateTime LastActivityOnUtc,
+ DateTime? EndedOnUtc,
+ double ConsumedDurationInSeconds,
+ MediaPositionResponse? LastPosition,
+ double LastProgressFraction,
+ int ConsecutivePagesRead
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionSummaryResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionSummaryResponse.cs
new file mode 100644
index 00000000..8b39265f
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/ConsumptionSummaryResponse.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents the consumption statistics of a user.
+///
+/// The Id of the user the statistics belong to.
+/// The total duration consumed over every recorded session, in seconds.
+/// The number of recorded sessions that count towards statistics.
+/// The number of recorded sessions that completed.
+/// The number of recorded sessions that stopped before they completed and count towards statistics.
+/// The fraction of the counted sessions that completed, between 0 and 1, or 0 when there is no counted session.
+/// The consumption statistics broken down by media kind.
+[DebuggerDisplay("UserId: {UserId}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record ConsumptionSummaryResponse(
+ Guid UserId,
+ double TotalConsumedDurationInSeconds,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ int StoppedSessionCount,
+ double CompletionRate,
+ IReadOnlyList MediaKindSummaries
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/MediaKindConsumptionSummaryResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/MediaKindConsumptionSummaryResponse.cs
new file mode 100644
index 00000000..2984741a
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/MediaKindConsumptionSummaryResponse.cs
@@ -0,0 +1,25 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents the consumption statistics of a user for one kind of media.
+///
+/// The kind of media the statistics belong to.
+/// The total duration consumed over every recorded session of the media kind, in seconds.
+/// The number of recorded sessions of the media kind that count towards statistics.
+/// The number of recorded sessions of the media kind that completed.
+/// The number of recorded sessions of the media kind that stopped before they completed and count towards statistics.
+/// The fraction of the counted sessions of the media kind that completed, between 0 and 1, or 0 when there is no counted session.
+[DebuggerDisplay("MediaKind: {MediaKind}; CountedSessionCount: {CountedSessionCount}")]
+public sealed record MediaKindConsumptionSummaryResponse(
+ MediaKind MediaKind,
+ double TotalConsumedDurationInSeconds,
+ int CountedSessionCount,
+ int CompletedSessionCount,
+ int StoppedSessionCount,
+ double CompletionRate
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/MediaPositionResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/MediaPositionResponse.cs
new file mode 100644
index 00000000..0c0d0f2e
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/MediaPositionResponse.cs
@@ -0,0 +1,19 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents a position reached in a media item during a consumption session.
+///
+/// The kind of representation used by the position.
+/// The position within the media item, in seconds, when the position is a time offset.
+/// The opaque locator within the media item, when the position is not a time offset.
+[DebuggerDisplay("Kind: {Kind}; TimeOffsetSeconds: {TimeOffsetSeconds}")]
+public sealed record MediaPositionResponse(
+ MediaPositionKind Kind,
+ double? TimeOffsetSeconds,
+ string? Location
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/ResumePointResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/ResumePointResponse.cs
new file mode 100644
index 00000000..7bb35a0b
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/ResumePointResponse.cs
@@ -0,0 +1,28 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
+using System;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents the point at which a user can resume consuming a media item.
+///
+/// The Id of the resume point.
+/// The Id of the media library that contains the media item.
+/// The Id of the media item to resume.
+/// The kind of media that is resumed.
+/// The position at which the media item can be resumed.
+/// The progress fraction at which the media item can be resumed.
+/// The date and time when the media item was last consumed.
+[DebuggerDisplay("Id: {Id}; MediaKind: {MediaKind}; MediaItemId: {MediaItemId}")]
+public sealed record ResumePointResponse(
+ Guid Id,
+ Guid LibraryId,
+ Guid MediaItemId,
+ MediaKind MediaKind,
+ MediaPositionResponse LastPosition,
+ double LastProgressFraction,
+ DateTime LastConsumedOnUtc
+);
diff --git a/src/Lumina.Contracts/Responses/MediaConsumption/TagConsumptionResponse.cs b/src/Lumina.Contracts/Responses/MediaConsumption/TagConsumptionResponse.cs
new file mode 100644
index 00000000..5508643c
--- /dev/null
+++ b/src/Lumina.Contracts/Responses/MediaConsumption/TagConsumptionResponse.cs
@@ -0,0 +1,21 @@
+#region ========================================================================= USING =====================================================================================
+using Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+using System.Diagnostics;
+#endregion
+
+namespace Lumina.Contracts.Responses.MediaConsumption;
+
+///
+/// Represents the consumption statistics of a tag or genre, grouped across media kinds.
+///
+/// The lowercase name of the tag or genre.
+/// Whether the entry is a genre or a tag.
+/// The number of distinct media items that carry the term and were consumed.
+/// The active duration consumed in the media items that carry the term, in seconds.
+[DebuggerDisplay("TagKind: {TagKind}; Name: {Name}; ConsumedItemCount: {ConsumedItemCount}")]
+public sealed record TagConsumptionResponse(
+ string Name,
+ TagKind TagKind,
+ int ConsumedItemCount,
+ double ConsumedDurationInSeconds
+);
diff --git a/src/Lumina.Domain.SharedKernel/Common/Enums/MediaConsumption/TagKind.cs b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaConsumption/TagKind.cs
new file mode 100644
index 00000000..84745686
--- /dev/null
+++ b/src/Lumina.Domain.SharedKernel/Common/Enums/MediaConsumption/TagKind.cs
@@ -0,0 +1,17 @@
+namespace Lumina.Domain.SharedKernel.Common.Enums.MediaConsumption;
+
+///
+/// Enumeration for the kinds of terms that a consumed media item can be classified by.
+///
+public enum TagKind
+{
+ ///
+ /// A genre.
+ ///
+ Genre,
+
+ ///
+ /// A tag.
+ ///
+ Tag
+}
diff --git a/src/Lumina.Domain/Common/Errors/Errors.MediaConsumption.cs b/src/Lumina.Domain/Common/Errors/Errors.MediaConsumption.cs
index ed452bce..9c57698c 100644
--- a/src/Lumina.Domain/Common/Errors/Errors.MediaConsumption.cs
+++ b/src/Lumina.Domain/Common/Errors/Errors.MediaConsumption.cs
@@ -14,6 +14,8 @@ public static partial class Errors
public static Error UnsupportedMediaKind => Error.Validation(description: nameof(UnsupportedMediaKind));
public static Error MediaKindCannotStartCompleted => Error.Forbidden(description: nameof(MediaKindCannotStartCompleted));
public static Error MediaKindCannotResume => Error.Forbidden(description: nameof(MediaKindCannotResume));
+ public static Error ConsumptionRecordNotFound => Error.NotFound(description: nameof(ConsumptionRecordNotFound));
+ public static Error MediaResumePointNotFound => Error.NotFound(description: nameof(MediaResumePointNotFound));
public static Error InvalidMediaPosition => Error.Validation(description: nameof(InvalidMediaPosition));
public static Error InvalidProgressFraction => Error.Validation(description: nameof(InvalidProgressFraction));
public static Error ConsumedDurationMustBeNonNegative => Error.Validation(description: nameof(ConsumedDurationMustBeNonNegative));