using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Data.Repositories;
namespace Chronos.Data.Processing;
///
/// The index's hero frame (, the frame the Library shows) follows the project's hero
/// (, a frame index; frame indices are positions).
///
public static class HeroFrame
{
///
/// The of a project whose hero went from to
/// : null when it did not change, else the frame at the new index, or
/// (the first frame shows) when there is none.
///
public static async Task EditAsync(ChronosDatabase db, Guid sequenceId, int? before, int? after, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(db);
if (before == after) return null;
if (after is not >= 0) return Guid.Empty;
var frames = await db.Frames.ListBySequenceAsync(sequenceId, after.Value - 1, 1, cancellationToken).ConfigureAwait(false);
return frames is [{ } frame] && frame.Index == after ? frame.Id : Guid.Empty;
}
}