package cli

import (
	"context"

	abci "git.cw.tr/mukan-network/mukan-consensus/abci/types"
	cmtbytes "git.cw.tr/mukan-network/mukan-consensus/libs/bytes"
	rpcclient "git.cw.tr/mukan-network/mukan-consensus/rpc/client"
	rpcclientmock "git.cw.tr/mukan-network/mukan-consensus/rpc/client/mock"
	coretypes "git.cw.tr/mukan-network/mukan-consensus/rpc/core/types"
	cmttypes "git.cw.tr/mukan-network/mukan-consensus/types"

	"git.cw.tr/mukan-network/mukan-sdk/client"
)

var _ client.CometRPC = (*MockCometRPC)(nil)

type MockCometRPC struct {
	rpcclientmock.Client

	responseQuery abci.ResponseQuery
}

// NewMockCometRPC returns a mock CometBFT RPC implementation.
// It is used for CLI testing.
func NewMockCometRPC(respQuery abci.ResponseQuery) MockCometRPC {
	return MockCometRPC{responseQuery: respQuery}
}

func (MockCometRPC) BroadcastTxSync(context.Context, cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) {
	return &coretypes.ResultBroadcastTx{Code: 0}, nil
}

func (m MockCometRPC) ABCIQueryWithOptions(
	_ context.Context,
	_ string,
	_ cmtbytes.HexBytes,
	_ rpcclient.ABCIQueryOptions,
) (*coretypes.ResultABCIQuery, error) {
	return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil
}
