Editor/Layers/ArchDraft.cs
namespace Sunless.Architecture;

// A placement in flight: an in-memory layer under an explicit parent, shown in the tree but never
// serialized until Finish binds the part the subtool just committed. Temporary ids are negative so
// they can never collide with the plan's own allocation.
public sealed class ArchDraft {
	static int nextTemporaryId = -1;

	public int Id { get; }
	public ArchKind Kind { get; }
	public ArchLayerRef? Parent { get; }
	public string Name { get; }
	public object Payload { get; }
	public bool Active { get; private set; } = true;
	public int ItemId { get; private set; }

	// The subtool that opened it. A draft outliving its owner is a row saying "placing" for a tool nobody
	// is holding, and nothing else on the plan can tell that it should have gone.
	public object Owner { get; }

	// Whether a gesture is actually in flight. A placement tool holds its draft for its whole life, so a
	// draft shown on the strength of that alone stands there through every idle minute claiming to be busy.
	public bool Standing { get; private set; }

	public ArchDraft( ArchKind kind, ArchLayerRef? parent, string name, object payload, object owner = null ) {
		Id = nextTemporaryId--;
		Kind = kind;
		Parent = parent;
		Name = name;
		Payload = payload;
		Owner = owner;
	}

	public void Show( bool standing ) => Standing = standing;

	// Discards the draft without touching the plan or the undo history.
	public void Cancel() => Active = false;

	// Binds the draft to the part that was just committed, then it leaves the tree.
	public void Finish( int itemId ) {
		ItemId = itemId;
		Active = false;
	}
}