using EnvelopeGenerator.ReceiverUI.Models.Constants;
namespace EnvelopeGenerator.ReceiverUI.Models;
///
/// Represents a signature position on a PDF page.
/// Coordinates stored in INCHES (GdPicture14 native unit).
/// Origin: Top-left corner, X increases right, Y increases down.
///
public class SignatureDto
{
/// Unique identifier.
public int Id { get; init; }
private double _x;
private double _y;
/// Horizontal position in INCHES from left edge.
public double X
{
get => _x * Factor;
init => _x = value;
}
/// Vertical position in INCHES from top edge.
public double Y
{
get => _y * Factor;
init => _y = value;
}
/// 1-based page number.
public int Page { get; init; }
/// Sender application type that created this signature.
public SenderAppType SenderAppType { get; init; }
private UnitOfLength _unitOfLength;
public SignatureDto Convert(UnitOfLength unitOfLength)
{
_unitOfLength = unitOfLength;
return this;
}
public double Factor
{
get
{
if (SenderAppType != SenderAppType.LegacyFormApp)
{
throw new NotImplementedException(
$"SenderAppType '{SenderAppType}' is not yet implemented. " +
$"Currently, only '{nameof(SenderAppType.LegacyFormApp)}' is supported. " +
$"Future implementations will handle '{nameof(SenderAppType.ReceiverUIBlazorApp)}' and other types.");
}
// LegacyFormApp uses GdPicture14 with INCHES
return _unitOfLength switch
{
UnitOfLength.Inch => 1.0, // No conversion needed: INCHES → INCHES
UnitOfLength.Point => 72.0, // INCHES → PDF Points: 1 inch = 72 points (PDF standard, NOT pixels!)
_ => throw new InvalidOperationException(
$"Unknown UnitOfLength: {_unitOfLength}. Expected '{nameof(UnitOfLength.Inch)}' or '{nameof(UnitOfLength.Point)}'.")
};
}
}
}
public static class SignatureDtoExtensions
{
///
/// Converts all signatures in the collection to the specified unit of length.
///
/// Type of the collection (IEnumerable, List, etc.)
/// Collection of SignatureDto objects to convert.
/// Target unit of measurement (Inch or Point).
/// The same collection with all signatures converted to the specified unit.
/// Thrown when signatures collection is null.
///
/// Usage:
///
/// var signatures = await SignatureService.GetAsync(envelopeKey);
/// var convertedSignatures = signatures.ConvertAll(UnitOfLength.Point);
///
/// Note: This method modifies each SignatureDto object in place and returns the same collection.
///
public static T Convert(this T signatures, UnitOfLength unitOfLength)
where T : IEnumerable
{
if (signatures == null)
throw new ArgumentNullException(nameof(signatures));
foreach (var signature in signatures)
{
signature.Convert(unitOfLength);
}
return signatures;
}
}