// Code generated by github.com/fjl/gencodec. DO NOT EDIT.

package params

import (
	"encoding/json"
	"errors"
	"math/big"

	"github.com/SecretBlockChain/go-secret/common"
	"github.com/SecretBlockChain/go-secret/common/math"
)

var _ = (*equalityConfigMarshaling)(nil)

// MarshalJSON marshals as JSON.
func (e EqualityConfig) MarshalJSON() ([]byte, error) {
	type EqualityConfig struct {
		Period              uint64                `json:"period"`
		Epoch               uint64                `json:"epoch"`
		MaxValidatorsCount  uint64                `json:"maxValidatorsCount"`
		MinCandidateBalance *math.HexOrDecimal256 `json:"minCandidateBalance" gencodec:"required"`
		GenesisTimestamp    uint64                `json:"genesisTimestamp"`
		Validators          []common.Address      `json:"validators"`
		Pool                common.Address        `json:"pool"`
		Rewards             EqualityRewards       `json:"rewards"`
	}
	var enc EqualityConfig
	enc.Period = e.Period
	enc.Epoch = e.Epoch
	enc.MaxValidatorsCount = e.MaxValidatorsCount
	enc.MinCandidateBalance = (*math.HexOrDecimal256)(e.MinCandidateBalance)
	enc.GenesisTimestamp = e.GenesisTimestamp
	enc.Validators = e.Validators
	enc.Pool = e.Pool
	enc.Rewards = e.Rewards
	return json.Marshal(&enc)
}

// UnmarshalJSON unmarshals from JSON.
func (e *EqualityConfig) UnmarshalJSON(input []byte) error {
	type EqualityConfig struct {
		Period              *uint64               `json:"period"`
		Epoch               *uint64               `json:"epoch"`
		MaxValidatorsCount  *uint64               `json:"maxValidatorsCount"`
		MinCandidateBalance *math.HexOrDecimal256 `json:"minCandidateBalance" gencodec:"required"`
		GenesisTimestamp    *uint64               `json:"genesisTimestamp"`
		Validators          []common.Address      `json:"validators"`
		Pool                *common.Address       `json:"pool"`
		Rewards             *EqualityRewards      `json:"rewards"`
	}
	var dec EqualityConfig
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.Period != nil {
		e.Period = *dec.Period
	}
	if dec.Epoch != nil {
		e.Epoch = *dec.Epoch
	}
	if dec.MaxValidatorsCount != nil {
		e.MaxValidatorsCount = *dec.MaxValidatorsCount
	}
	if dec.MinCandidateBalance == nil {
		return errors.New("missing required field 'minCandidateBalance' for EqualityConfig")
	}
	e.MinCandidateBalance = (*big.Int)(dec.MinCandidateBalance)
	if dec.GenesisTimestamp != nil {
		e.GenesisTimestamp = *dec.GenesisTimestamp
	}
	if dec.Validators != nil {
		e.Validators = dec.Validators
	}
	if dec.Pool != nil {
		e.Pool = *dec.Pool
	}
	if dec.Rewards != nil {
		e.Rewards = *dec.Rewards
	}
	return nil
}
