using xBotService.Models; using xCommons.Extensions; using xExceptions.Constants; using xBotService.Models.Dtos; using xBotService.Configuration; using xBotService.Models.Entities; namespace xBotService.Extensions { public static class XBotServiceExtensions { /// /// Make Sure a Response Message is Valid ... /// /// public static void EnsureBotResponseSucceed( this XBotResponse source ) { // var isValid = !source.IsNull() && source.Ok; if (!isValid) { XException.ActionFailed.Throw(); } } /// /// Validate a Message Send Request ... /// /// /// public static bool IsValid( this XBotSendMessageRequest source ) { // var result = !source.IsNull() && source.ChatId > 0; // return result; } /// /// Check a User is Verified or not ... /// /// /// public static bool IsVerified( this XBotUser source ) { // var result = !source.IsNullOrDefault() && source.VerifiedOn.HasValue; // return result; } /// /// Check a User is Verified or not ... /// /// /// public static bool IsVerified( this XBotUserDto source ) { // var result = !source.IsNullOrDefault() && source.VerifiedOn.HasValue; // return result; } /// /// Check a User's Verification Code is Expired or not ... /// /// /// /// public static bool IsExpired( this XBotUser source, XBotServiceConfiguration configuration ) { // // Validate ... if (configuration.IsNull() || source.IsNullOrDefault() || !source.VerifiedOn.HasValue || configuration.VerificationCodeTTL <= 0) { XException.InvalidArgs.Throw(); } // var result = source.VerifiedOn.Value.IsExpiredTTL(configuration.VerificationCodeTTL); return result; } /// /// Check a User's Verification Code is Expired or not ... /// /// /// /// public static bool IsExpired( this XBotUserDto source, XBotServiceConfiguration configuration ) { // // Validate ... if (configuration.IsNull() || source.IsNullOrDefault() || !source.VerifiedOn.HasValue || configuration.VerificationCodeTTL <= 0) { XException.InvalidArgs.Throw(); } // var result = source.VerifiedOn.Value.IsExpiredTTL(configuration.VerificationCodeTTL); return result; } /// /// Normalize ot Update Request ... /// /// /// public static XBotUpdatesRequest Normalize( this XBotUpdatesRequest source ) { // if (source.IsNull()) { source = new(); } // // Limit ... if (source.Limit <= 0 || source.Limit > 100) { source.Limit = 100; } // if (source.Offset < 0) { source.Offset = 0; } // if (source.Timeout <= 30) { source.Timeout = 30; } // return source; } /// /// Converts To Dto ... /// /// /// public static XBotSendMessageRequestDto ToDto( this XBotSendMessageRequest source ) { // XBotSendMessageRequestDto result = null; if (source.IsNull()) { return result; } // result = new(); result = source.MapConvert(); // return result; } } }