using System.Threading;
using System.Threading.Tasks;
using Svrnty.CQRS.Events.Abstractions.EventStore;
namespace Svrnty.CQRS.Events.Abstractions.Schema;
///
/// Defines a contract for upcasting events from one version to another.
///
/// The source event version type.
/// The target event version type.
///
///
/// Upcasting Strategies:
///
///
/// 1. Convention-based (Recommended):
/// Define a static UpcastFrom method on the target type:
///
/// public static UserCreatedEventV2 UpcastFrom(UserCreatedEventV1 v1)
/// {
/// return new UserCreatedEventV2 { ... };
/// }
///
///
///
/// 2. Interface-based (Advanced):
/// Implement IEventUpcaster for complex transformations:
///
/// public class UserCreatedEventUpcaster : IEventUpcaster<UserCreatedEventV1, UserCreatedEventV2>
/// {
/// public async Task<UserCreatedEventV2> UpcastAsync(UserCreatedEventV1 from, CancellationToken ct)
/// {
/// // Complex logic here (database lookups, calculations, etc.)
/// return new UserCreatedEventV2 { ... };
/// }
/// }
///
///
///
public interface IEventUpcaster
where TFrom : ICorrelatedEvent
where TTo : ICorrelatedEvent
{
///
/// Upcasts an event from the source version to the target version.
///
/// The source event version.
/// Cancellation token.
/// The upcast event at the target version.
///
///
/// Implementations should:
/// - Preserve EventId, CorrelationId, and OccurredAt from the source event
/// - Map all compatible properties
/// - Provide sensible defaults for new properties
/// - Perform any necessary data transformations
///
///
Task UpcastAsync(TFrom from, CancellationToken cancellationToken = default);
}