package ibc

import (
	sdk "git.cw.tr/mukan-network/mukan-sdk/types"

	client "git.cw.tr/mukan-network/mukan-ibc/modules/core/02-client"
	clientv2 "git.cw.tr/mukan-network/mukan-ibc/modules/core/02-client/v2"
	connection "git.cw.tr/mukan-network/mukan-ibc/modules/core/03-connection"
	channel "git.cw.tr/mukan-network/mukan-ibc/modules/core/04-channel"
	channelv2 "git.cw.tr/mukan-network/mukan-ibc/modules/core/04-channel/v2"
	"git.cw.tr/mukan-network/mukan-ibc/modules/core/keeper"
	"git.cw.tr/mukan-network/mukan-ibc/modules/core/types"
)

// InitGenesis initializes the ibc state from a provided genesis
// state.
func InitGenesis(ctx sdk.Context, k keeper.Keeper, gs *types.GenesisState) {
	client.InitGenesis(ctx, k.ClientKeeper, gs.ClientGenesis)
	clientv2.InitGenesis(ctx, k.ClientV2Keeper, gs.ClientV2Genesis)
	connection.InitGenesis(ctx, k.ConnectionKeeper, gs.ConnectionGenesis)
	channel.InitGenesis(ctx, k.ChannelKeeper, gs.ChannelGenesis)
	channelv2.InitGenesis(ctx, k.ChannelKeeperV2, gs.ChannelV2Genesis)
}

// ExportGenesis returns the ibc exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
	return &types.GenesisState{
		ClientGenesis:     client.ExportGenesis(ctx, k.ClientKeeper),
		ClientV2Genesis:   clientv2.ExportGenesis(ctx, k.ClientV2Keeper),
		ConnectionGenesis: connection.ExportGenesis(ctx, k.ConnectionKeeper),
		ChannelGenesis:    channel.ExportGenesis(ctx, k.ChannelKeeper),
		ChannelV2Genesis:  channelv2.ExportGenesis(ctx, k.ChannelKeeperV2),
	}
}
