You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: remote_secondary_forked_alertmanager.go
    path of file: ./repos/grafana/pkg/services/ngalert/remote
    
    the code of the file until where you have to start completion: package remote

import (
	"context"
	"fmt"
	"sync"
	"time"

	"github.com/grafana/grafana/pkg/infra/log"
	apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
	"github.com/grafana/grafana/pkg/services/ngalert/models"
	"github.com/grafana/grafana/pkg/services/ngalert/notifier"
)

type configStore interface {
	GetLatestAlertmanagerConfiguration(c
    
func (fam *RemoteSecondaryForkedAlertmanager) ApplyConfig(ctx context.Context, config *models.AlertConfiguration) error {
	var wg sync.WaitGroup
	wg.Add(1)
	// Figure out if we need to sync the external Alertmanager in another goroutine.
	go func() {
		defer wg.Done()
		// If the Alertmanager has not been marked as "ready" yet, delegate the call to the remote Alertmanager.
		// This will perform a readiness check and sync the Alertmanagers.
		if !fam.remote.Ready() {
			if err := fam.remote.ApplyConfig(ctx, config); err != nil {
				fam.log.Error("Error applying config to the remote Alertmanager", "err", err)
				return
			}
			fam.lastSync = time.Now()
			return
		}

		// If the Alertmanager was marked as ready but the sync interval has elapsed, sync the Alertmanagers.
		if time.Since(fam.lastSync) >= fam.syncInterval {
			fam.log.Debug("Syncing configuration and state with the remote Alertmanager", "lastSync", fam.lastSync)
			cfgErr := fam.remote.CompareAndSendConfiguration(ctx, config)
			if cfgErr != nil {
				fam.log.Error("Unable to upload the configuration to the remote Alertmanager", "err", cfgErr)
			}

			stateErr := fam.remote.CompareAndSendState(ctx)
			if stateErr != nil {
				fam.log.Error("Unable to upload the state to the remote Alertmanager", "err", stateErr)
			}
			fam.log.Debug("Finished syncing configuration and state with the remote Alertmanager")

			if cfgErr == nil && stateErr == nil {
				fam.lastSync = time.Now()
			}
		}
	}()

	// Call ApplyConfig on the internal Alertmanager - we only care about errors for this one.
	err := fam.internal.ApplyConfig(ctx, config)
	wg.Wait()
	return err
}