package main

import (
	"context"

	"github.com/fiskerinc/cloud-services/services/gateway/controllers"
	"github.com/fiskerinc/cloud-services/services/gateway/server"
	"github.com/fiskerinc/cloud-services/services/gateway/services"
	"github.com/fiskerinc/cloud-services/services/gateway/sloppy"

	"github.com/fiskerinc/cloud-services/pkg/logger"
	"github.com/fiskerinc/cloud-services/pkg/tracer"
	"github.com/fiskerinc/cloud-services/pkg/utils/app"
)

func init() {
	app.Setup("gateway", cleanup)
}

func main() {
	defer cleanup()

	tracer.Start()
	defer tracer.Stop()

	const port string = ":8077"
	const kafkaTopic string = "ota_update"

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	// Initiate vin blocking list early
	sloppy.GetVINBlocker()

	go controllers.HealthCheck()
	go server.StartRedisQueue(ctx)
	go server.StartRedisSubscriptions(ctx)
	go services.GetConnections().RunExpiration(ctx)
	go server.StartHTTP(ctx, port)
	select {}
}

func cleanup() {
	logger.Close()
}
