using System;
namespace GitHub.Runner.Worker.Dap.StepCommands
{
///
/// Records a modification made to a step during a debug session.
/// Used for change tracking and export diff generation.
///
public class StepChange
{
///
/// The type of change made.
///
public ChangeType Type { get; set; }
///
/// The original 1-based index of the step (before any modifications).
/// For Added steps, this is -1.
///
public int OriginalIndex { get; set; } = -1;
///
/// The current 1-based index of the step (after all modifications).
/// For Removed steps, this is -1.
///
public int CurrentIndex { get; set; } = -1;
///
/// Snapshot of the step before modification (for Modified/Moved/Removed).
///
public StepInfo OriginalStep { get; set; }
///
/// The step after modification (for Added/Modified/Moved).
/// For Removed steps, this is null.
///
public StepInfo ModifiedStep { get; set; }
///
/// Timestamp when the change was made.
///
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
///
/// Description of the change for display purposes.
///
public string Description { get; set; }
///
/// Creates a change record for an added step.
///
public static StepChange Added(StepInfo step, int index)
{
return new StepChange
{
Type = ChangeType.Added,
OriginalIndex = -1,
CurrentIndex = index,
ModifiedStep = step,
Description = $"Added step '{step.Name}' at position {index}"
};
}
///
/// Creates a change record for a modified step.
///
public static StepChange Modified(StepInfo original, StepInfo modified, string changeDescription = null)
{
return new StepChange
{
Type = ChangeType.Modified,
OriginalIndex = original.Index,
CurrentIndex = modified.Index,
OriginalStep = original,
ModifiedStep = modified,
Description = changeDescription ?? $"Modified step '{original.Name}' at position {original.Index}"
};
}
///
/// Creates a change record for a removed step.
///
public static StepChange Removed(StepInfo step)
{
return new StepChange
{
Type = ChangeType.Removed,
OriginalIndex = step.Index,
CurrentIndex = -1,
OriginalStep = step,
Description = $"Removed step '{step.Name}' from position {step.Index}"
};
}
///
/// Creates a change record for a moved step.
///
public static StepChange Moved(StepInfo original, int newIndex)
{
var modified = new StepInfo
{
Index = newIndex,
Name = original.Name,
Type = original.Type,
TypeDetail = original.TypeDetail,
Status = original.Status,
Action = original.Action,
Step = original.Step,
OriginalIndex = original.Index,
Change = ChangeType.Moved
};
return new StepChange
{
Type = ChangeType.Moved,
OriginalIndex = original.Index,
CurrentIndex = newIndex,
OriginalStep = original,
ModifiedStep = modified,
Description = $"Moved step '{original.Name}' from position {original.Index} to {newIndex}"
};
}
///
/// Returns a human-readable summary of this change.
///
public override string ToString()
{
return Description ?? $"{Type} step at index {OriginalIndex} -> {CurrentIndex}";
}
}
}