// TODO: change timer to once per hour (0 0 * * * *)
        public static async Task Run(
            [TimerTrigger("0 */1 * * * *")] TimerInfo myTimer,
            [Queue("srkwfound")] CloudQueue cloudQueue,
            [Table("EmailList")] CloudTable cloudTable,
            [SendGrid(ApiKey = "SendGridKey")] IAsyncCollector <SendGridMessage> messageCollector,
            ILogger log)
        {
            log.LogInformation("Checking if there are items in queue");
            await cloudQueue.FetchAttributesAsync();

            if (cloudQueue.ApproximateMessageCount == 0)
            {
                log.LogInformation("No items in queue");
                return;
            }

            log.LogInformation("Creating email message");
            var body = await CreateBody(cloudQueue);

            log.LogInformation("Retrieving email list and sending notifications");
            foreach (var emailEntity in EmailHelpers.GetEmailEntities(cloudTable, "Subscriber"))
            {
                var email = EmailHelpers.CreateEmail(Environment.GetEnvironmentVariable("SenderEmail"),
                                                     emailEntity.Email, "Notification: Orca detected!", body);
                await messageCollector.AddAsync(email);
            }
        }
        public static async Task Run(
            [CosmosDBTrigger(
                 databaseName: "predictions",
                 collectionName: "metadata",
                 ConnectionStringSetting = "aifororcasmetadatastore_DOCUMENTDB",
                 LeaseCollectionName = "leases",
                 LeaseCollectionPrefix = "moderator",
                 CreateLeaseCollectionIfNotExists = true)] IReadOnlyList <Document> input,
            [Table("EmailList")] CloudTable cloudTable,
            [SendGrid(ApiKey = "SendGridKey")] IAsyncCollector <SendGridMessage> messageCollector,
            ILogger log)
        {
            if (input == null || input.Count == 0)
            {
                log.LogInformation("No updated records");
                return;
            }

            var      newDocumentCreated = false;
            DateTime?documentTimeStamp  = null;

            foreach (var document in input)
            {
                if (!document.GetPropertyValue <bool>("reviewed"))
                {
                    newDocumentCreated = true;
                    documentTimeStamp  = document.GetPropertyValue <DateTime>("timestamp");
                    break;
                }
            }

            if (!newDocumentCreated)
            {
                log.LogInformation("No unreviewed records");
                return;
            }

            // TODO: make better email
            string body = EmailTemplate.GetModeratorEmailBody(documentTimeStamp);

            log.LogInformation("Retrieving email list and sending notifications");
            foreach (var emailEntity in EmailHelpers.GetEmailEntities(cloudTable, "Moderator"))
            {
                var email = EmailHelpers.CreateEmail(Environment.GetEnvironmentVariable("SenderEmail"),
                                                     emailEntity.Email, "New Orca Call Identified", body);
                await messageCollector.AddAsync(email);
            }
        }