package genexchain

import (
	storetypes "cosmossdk.io/store/types"
	upgradetypes "cosmossdk.io/x/upgrade/types"
)

// RegisterUpgradeHandlers registers upgrade handlers for chain upgrades
func (app GenexApp) RegisterUpgradeHandlers() {
	// Genex Chain v1.0.0 — initial release, no upgrade handlers needed yet.
	// Future upgrades will be registered here:
	//
	// app.UpgradeKeeper.SetUpgradeHandler(
	//     "v1.1.0",
	//     func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
	//         // migration logic
	//         return app.ModuleManager.RunMigrations(ctx, app.Configurator(), fromVM)
	//     },
	// )

	upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
	if err != nil {
		panic(err)
	}

	// Check if we need store upgrades
	if upgradeInfo.Name != "" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
		storeUpgrades := storetypes.StoreUpgrades{Added: []string{}}
		app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
	}
}
