package main

import (
	"encoding/json"
	"fmt"
	"log"

	"go.uber.org/zap"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/app"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize"
)

func main() {
	logger, err := zap.NewProduction(zap.AddStacktrace(zap.DPanicLevel))
	if err != nil {
		log.Fatalf("failed to init zap logger: %v", err)
	}

	config, err := initialize.Configuration(".env.test")
	if err != nil {
		logger.Fatal("failed to init config: %v", zap.Error(err))
	}

	configJSON, err := json.MarshalIndent(config, "", "\t")
	if err != nil {
		logger.Error("failed to translate config struct to json for print inromation: %v", zap.Error(err))
	}

	fmt.Println("env configuration: \n", string(configJSON))

	if err := app.Run(config, logger); err != nil {
		logger.Fatal("failed to run app: %v", zap.Error(err))
	}
}
