package cmd

import (
	"github.com/navidrome/navidrome/db"
	"github.com/navidrome/navidrome/log"
	"github.com/spf13/cobra"
)

var indexCmd = &cobra.Command{
	Use:   "index",
	Short: "Manage Meilisearch index",
}

var indexFullCmd = &cobra.Command{
	Use:   "full",
	Short: "Full re-index of all media files, albums, and artists",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := cmd.Context()
		defer db.Init(ctx)()

		ds := CreateDataStore()

		err := ds.ReindexAll(ctx)
		if err != nil {
			log.Error("Error during full re-index", err)
		} else {
			log.Info("Full re-index completed successfully")
		}
	},
}

func init() {
	rootCmd.AddCommand(indexCmd)
	indexCmd.AddCommand(indexFullCmd)
}
