// coin.go
package coin

import (
	"net"
	"pool/internal/db"

	"pool/internal/gbt/alph/http"
	"pool/internal/utility"

	"github.com/btcsuite/btcd/rpcclient"
	kaspad "github.com/kaspanet/kaspad/infrastructure/network/rpcclient"
	"github.com/redis/go-redis/v9"
	"github.com/zeromq/goczmq"
	"go.uber.org/zap"
	"gopkg.in/natefinch/lumberjack.v2"
)

type RpcConfig struct {
	Host    string `json:"host"`
	Port    string `json:"port"`
	ApiHost string `json:"apiHost"`
	ApiPort string `json:"apiPort"`
	ApiKey  string `json:"apiKey"`
	Testnet string `json:"testnet"`
	Type    string `json:"type"`
	User    string `json:"user"`
	Pass    string `json:"pass"`
	ZmqSub  string `json:"zmqsub"`
	Timeout int    `json:"timeout"`
}

type ZmqConfig struct {
	Pub string `json:"pub"`
	Sub string `json:"sub"`
}

type ProfitConfig struct {
	Push string `json:"push"`
}

type GbtConfig struct {
	Rpc      RpcConfig               `json:"rpc"`
	Zmq      ZmqConfig               `json:"zmq"`
	Redis    utility.RedisConfig     `json:"redis"`
	Profit   ProfitConfig            `json:"profit"`
	Zaplog   zap.Config              `json:"zap"`
	Logrotae utility.LogRotateConfig `json:"logrotate"`
}

type GbtContext struct {
	DbCtx *db.DbContext

	NodeSubCh *goczmq.Sock

	PubCh *goczmq.Sock
	SubCh *goczmq.Sock

	PushCh *goczmq.Sock

	Started        bool
	Config         GbtConfig
	Client         *rpcclient.Client
	ClientAlph     *net.Conn
	ClientAlphApi  *http.HttpClient
	ClientEnx      *kaspad.RPCClient
	ExitNotifyChan chan bool
	ExitGbtChan    chan bool
	ExitBlockChan  chan bool

	//AlivingChan chan bool
	FlagAliving     int32
	FlagAlivingExit int32

	Log  *zap.Logger
	LogR *lumberjack.Logger

	RedisClient *redis.Client

	Coin string

	MinerAddrs     []string
	MinerAddrIndex int

	/*Blocks int64

	Reward float64
	Fee    float64*/
}