func GetNextTimeout(fs *firestore.Client) (time.Time, string, *Webhook, error) {
	// Get refs to all the documents in the collection
	docrefs, err := fs.Collection(WebhookCollection).DocumentRefs(context.Background()).GetAll()
	if err != nil {
		return time.Now(), "", nil, err
	}

	// Initialize target to after any webhook timeout point
	target := time.Now().AddDate(100, 0, 0) // nolint:gomnd // Just some random large duration
	// Save the latest
	var targetWebhook *Webhook
	var targetID string
	for _, docref := range docrefs {
		docsnap, err := docref.Get(context.Background())
		if err != nil {
			continue // Just ignore any documents that can't be fetched, either because they don't have snapshots, or some other error
		}

		// Parse the document into webhook
		var data Webhook
		err = docsnap.DataTo(&data)
		if err != nil {
			continue
		}

		// Get the timeout as a duration
		timeoutdur := time.Duration(data.Timeout) * time.Second

		// Is the timeout point of the webhook more recent than the most
		// recently recorded
		if current := data.LastTriggered.Add(timeoutdur); current.Before(target) {
			target = current
			targetWebhook = &data
			targetID = docref.ID
		}
	}

	return target, targetID, targetWebhook, nil
}
// GetNextTimeout return the next timepoint where a webhook should be invoked.
// Returns the time of the next timeout, the id and webhook body of the next webhook to get timed out, and maybe an error.
GetNextTimeout return the next timepoint where a webhook should be invoked.
Returns the time of the next timeout, the id and webhook body of the next webhook to get timed out, and maybe an error.
// GetNextTimeout return the next timepoint where a webhook should be invoked . // Returns the time of the next timeout the id and webhook body of the next webhook to get timed out and maybe an error .
func GetNextTimeout(fs *firestore.Client) (time.Time, string, *Webhook, error) {
	docrefs, err := fs.Collection(WebhookCollection).DocumentRefs(context.Background()).GetAll()
	if err != nil {
		return time.Now(), "", nil, err
	}
	target := time.Now().AddDate(100, 0, 0) 
	var targetWebhook *Webhook
	var targetID string
	for _, docref := range docrefs {
		docsnap, err := docref.Get(context.Background())
		if err != nil {
			continue 
		}
		var data Webhook
		err = docsnap.DataTo(&data)
		if err != nil {
			continue
		}
		timeoutdur := time.Duration(data.Timeout) * time.Second
		if current := data.LastTriggered.Add(timeoutdur); current.Before(target) {
			target = current
			targetWebhook = &data
			targetID = docref.ID
		}
	}
	return target, targetID, targetWebhook, nil
}
func GetNextTimeout ( fs * firestore . Client ) ( time . Time , string , * Webhook , error ) { docrefs , err := fs . Collection ( WebhookCollection ) . DocumentRefs ( context . Background ( ) ) . GetAll ( ) if err != nil { return time . Now ( ) , " " , nil , err } target := time . Now ( ) . AddDate ( 100 , 0 , 0 ) var targetWebhook * Webhook var targetID string for _ , docref := range docrefs { docsnap , err := docref . Get ( context . Background ( ) ) if err != nil { continue } var data Webhook err = docsnap . DataTo ( & data ) if err != nil { continue } timeoutdur := time . Duration ( data . Timeout ) * time . Second if current := data . LastTriggered . Add ( timeoutdur ) ; current . Before ( target ) { target = current targetWebhook = & data targetID = docref . ID } } return target , targetID , targetWebhook , nil }
GetNextTimeout return the next timepoint where a webhook should be invoked.
GetNextTimeout return the next timepoint where a webhook should be invoked .
// Get refs to all the documents in the collection // Initialize target to after any webhook timeout point // nolint:gomnd // Just some random large duration // Save the latest // Just ignore any documents that can't be fetched, either because they don't have snapshots, or some other error // Parse the document into webhook // Get the timeout as a duration // Is the timeout point of the webhook more recent than the most // recently recorded