// Manually sync a poc application to Salesforce
// To compile: GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w " -v -o sync_poc ./sync_poc_application.go
// Note: poc_application_id is the ID of poc_applications table, not a tenant ID.
package main

import (
	"context"
	"flag"
	"fmt"

	"github.com/tidbcloud/account/central/jobs"
	"github.com/tidbcloud/account/central/server"
	"github.com/tidbcloud/account/central/utils"
	"github.com/tidbcloud/account/commons/config"
	grpc_errcode "github.com/tidbcloud/account/pkg/grpc/middleware/errcode"
	"github.com/tidbcloud/tiinf/monitor/tilog"
	"go.uber.org/zap"
)

const (
	defaultConfigPath = "/etc/dbaas/config.yaml"
)

func main() {
	ctx := context.Background()
	var configPath string
	flag.StringVar(&configPath, "config-path", defaultConfigPath, "DBaaS configuration file path")
	flag.Parse()

	err := config.InitConfig(configPath)
	if err != nil {
		panic(fmt.Sprintf("Initialize configuration failed: %+v", err))
	}

	err = utils.SetupLoggerAndSentry()
	if err != nil {
		panic(fmt.Sprintf("Initialize logger and sentry failed: %+v", err))
	}

	_, err = server.NewServer("Sync Poc Application", server.GRPCAuthTypeDumb, grpc_errcode.ErrorFormatDefault)
	if err != nil {
		panic(fmt.Sprintf("Failed to create server: %+v", err))
	}

	var req = []byte(`{"poc_application_id": 30009}`)

	err = jobs.SyncPocApplication(context.Background(), req)
	if err != nil {
		tilog.Error(ctx, "sync failed", zap.Error(err))
	}
}
