namespace QRBee.Core.Data
{
public record ClientToMerchantResponse
{
public MerchantToClientRequest MerchantRequest { get; set; }
public string ClientId { get; set; }
public DateTime TimeStampUTC { get; set; }
public string ClientSignature { get; set; }
public string EncryptedClientCardData { get; set; }
///
/// Convert ClientToMerchantResponse to string to be used as QR Code source (along with client signature)
///
/// Converted string
public string AsQRCodeString() => $"{ClientId}|{TimeStampUTC:O}|{ClientSignature}";
public string AsDataForSignature() => $"{ClientId}|{TimeStampUTC:O}|{MerchantRequest.AsQRCodeString()}";
///
/// Convert from string
///
/// A string representation of ClientToMerchantResponse
/// Converted string
/// Thrown if the input string is incorrect
public static ClientToMerchantResponse FromString(string input)
{
var s = input.Split('|');
if (s.Length < 3)
{
throw new ApplicationException($"Expected 3 or more elements but got {s.Length}");
}
var res = new ClientToMerchantResponse()
{
ClientId = s[0],
TimeStampUTC = DateTime.ParseExact(s[1], "O", null),
ClientSignature = s[2]
};
return res;
}
}
}