package command

import (
	"context"
	"fmt"
	"git.gocasts.ir/ebhomengo/niki/pkg/logger"
	"git.gocasts.ir/ebhomengo/niki/shoppingbasketapp"
	"github.com/labstack/gommon/log"
	"github.com/spf13/cobra"
)

var ServeCmd = &cobra.Command{
	Use:   "serve",
	Short: "Start shoppingbasket service",
	Long:  `This command starts the main shoppingbasket service.`,
	Run: func(cmd *cobra.Command, args []string) {

	},
}

func serve() {
	var cfg = loadAppConfig()

	logger.Init(cfg.Logger)
	l := logger.L()

	l.Info("Starting shoppingbasket service...")

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	app, err := shoppingbasketapp.Setup(ctx, cfg)
	if err != nil {
		l.Error("failed initialize shopping basket app", "error", err)
		log.Fatalf(fmt.Sprintf("error starting shopping basket app: %v", err))
	}

	app.Start()
}

func init() {
	RootCmd.AddCommand(ServeCmd)
}
