using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Exceptions; #if NETFRAMEWORK using System; using System.Linq; #endif namespace EnvelopeGenerator.Domain.Interfaces { public interface IEnvelope { int? EnvelopeTypeId { get; set; } byte[] #if nullable ? #endif DocResult { get; } } public static class EnvelopeExtensions { public static bool IsReadAndConfirm(this IEnvelope envelope) { return envelope.EnvelopeTypeId == 2; } public static bool IsReadAndSign(this IEnvelope envelope) { return envelope.EnvelopeTypeId != 2; } public static bool IsBurned(this IEnvelope envelope) { return envelope.DocResult != null; } public static EnvelopeType? Type(this IEnvelope envelope) { if (envelope.EnvelopeTypeId is int envelopeTypeId) return envelopeTypeId.ToEnvelopeType(); return null; } public static void SetType(this IEnvelope envelope, EnvelopeType type) { envelope.EnvelopeTypeId = (int)type; } public static TEnvelope WithType(this TEnvelope envelope, EnvelopeType type) where TEnvelope : IEnvelope { envelope.SetType(type); return envelope; } } }