// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.

package schema

import "encoding/json"
import "fmt"

type Config struct {
	// List of addresses to listen on for libp2p traffic.
	ListenAddresses []string `json:"listenAddresses,omitempty"`

	// Trusted peers in the network.
	Peers []ConfigPeersElem `json:"peers,omitempty"`

	// This node's private key.
	PrivateKey string `json:"privateKey"`

	// The services this node provides via the Service Network.
	Services ConfigServices `json:"services,omitempty"`
}

type ConfigPeersElem struct {
	// PeerID of this peer.
	Id string `json:"id"`

	// Friendly name for this peer. (optional)
	Name string `json:"name,omitempty"`

	// Networks to route to this peer. (optional)
	Routes []ConfigPeersElemRoutesElem `json:"routes,omitempty"`
}

type ConfigPeersElemRoutesElem struct {
	// Network specification.
	Net string `json:"net"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ConfigPeersElemRoutesElem) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["net"]; raw != nil && !ok {
		return fmt.Errorf("field net in ConfigPeersElemRoutesElem: required")
	}
	type Plain ConfigPeersElemRoutesElem
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	*j = ConfigPeersElemRoutesElem(plain)
	return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ConfigPeersElem) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["id"]; raw != nil && !ok {
		return fmt.Errorf("field id in ConfigPeersElem: required")
	}
	type Plain ConfigPeersElem
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if v, ok := raw["name"]; !ok || v == nil {
		plain.Name = ""
	}
	if v, ok := raw["routes"]; !ok || v == nil {
		plain.Routes = []ConfigPeersElemRoutesElem{}
	}
	*j = ConfigPeersElem(plain)
	return nil
}

// The services this node provides via the Service Network.
type ConfigServices map[string]struct {
	// Acl corresponds to the JSON schema field "acl".
	Acl *ConfigServicesValueAcl `json:"acl,omitempty"`

	// Target address.
	Target string `json:"target"`
}

type ConfigServicesValueAcl struct {
	// List of peers that are explicitly not allowed to connect.
	Blacklist []string `json:"blacklist,omitempty"`

	// Whether to enable whitelist enforcement.
	EnableWhitelist bool `json:"enableWhitelist,omitempty"`

	// List of peers that are allowed to connect.
	Whitelist []string `json:"whitelist,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *ConfigServicesValueAcl) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	type Plain ConfigServicesValueAcl
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if v, ok := raw["blacklist"]; !ok || v == nil {
		plain.Blacklist = []string{}
	}
	if v, ok := raw["enableWhitelist"]; !ok || v == nil {
		plain.EnableWhitelist = false
	}
	if v, ok := raw["whitelist"]; !ok || v == nil {
		plain.Whitelist = []string{}
	}
	*j = ConfigServicesValueAcl(plain)
	return nil
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *Config) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["privateKey"]; raw != nil && !ok {
		return fmt.Errorf("field privateKey in Config: required")
	}
	type Plain Config
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if v, ok := raw["listenAddresses"]; !ok || v == nil {
		plain.ListenAddresses = []string{
			"/ip4/0.0.0.0/tcp/8001",
			"/ip4/0.0.0.0/udp/8001/quic-v1",
			"/ip6/::/tcp/8001",
			"/ip6/::/udp/8001/quic-v1",
		}
	}
	if v, ok := raw["peers"]; !ok || v == nil {
		plain.Peers = []ConfigPeersElem{}
	}
	if v, ok := raw["services"]; !ok || v == nil {
		plain.Services = ConfigServices{}
	}
	*j = Config(plain)
	return nil
}
