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

package test

import "encoding/json"
import "fmt"
import yaml "gopkg.in/yaml.v3"
import "time"

type Pointer struct {
	// BoolWithDefault corresponds to the JSON schema field "boolWithDefault".
	BoolWithDefault *bool `json:"boolWithDefault,omitempty,omitzero" yaml:"boolWithDefault,omitempty" mapstructure:"boolWithDefault,omitempty"`

	// DurationWithDefault corresponds to the JSON schema field "durationWithDefault".
	DurationWithDefault *time.Duration `json:"durationWithDefault,omitempty,omitzero" yaml:"durationWithDefault,omitempty" mapstructure:"durationWithDefault,omitempty"`

	// IntWithDefault corresponds to the JSON schema field "intWithDefault".
	IntWithDefault *int `json:"intWithDefault,omitempty,omitzero" yaml:"intWithDefault,omitempty" mapstructure:"intWithDefault,omitempty"`

	// NormalDefault corresponds to the JSON schema field "normalDefault".
	NormalDefault string `json:"normalDefault,omitempty,omitzero" yaml:"normalDefault,omitempty" mapstructure:"normalDefault,omitempty"`

	// NormalOptional corresponds to the JSON schema field "normalOptional".
	NormalOptional *string `json:"normalOptional,omitempty,omitzero" yaml:"normalOptional,omitempty" mapstructure:"normalOptional,omitempty"`

	// OptionalIntNonPointer corresponds to the JSON schema field
	// "optionalIntNonPointer".
	OptionalIntNonPointer int `json:"optionalIntNonPointer,omitempty,omitzero" yaml:"optionalIntNonPointer,omitempty" mapstructure:"optionalIntNonPointer,omitempty"`

	// OptionalStringNonPointer corresponds to the JSON schema field
	// "optionalStringNonPointer".
	OptionalStringNonPointer string `json:"optionalStringNonPointer,omitempty,omitzero" yaml:"optionalStringNonPointer,omitempty" mapstructure:"optionalStringNonPointer,omitempty"`

	// RequiredIntNonPointer corresponds to the JSON schema field
	// "requiredIntNonPointer".
	RequiredIntNonPointer int `json:"requiredIntNonPointer" yaml:"requiredIntNonPointer" mapstructure:"requiredIntNonPointer"`

	// RequiredIntPointer corresponds to the JSON schema field "requiredIntPointer".
	RequiredIntPointer *int `json:"requiredIntPointer" yaml:"requiredIntPointer" mapstructure:"requiredIntPointer"`

	// SliceWithDefault corresponds to the JSON schema field "sliceWithDefault".
	SliceWithDefault []string `json:"sliceWithDefault,omitempty,omitzero" yaml:"sliceWithDefault,omitempty" mapstructure:"sliceWithDefault,omitempty"`

	// StringWithDefault corresponds to the JSON schema field "stringWithDefault".
	StringWithDefault *string `json:"stringWithDefault,omitempty,omitzero" yaml:"stringWithDefault,omitempty" mapstructure:"stringWithDefault,omitempty"`
}

// UnmarshalJSON implements json.Unmarshaler.
func (j *Pointer) UnmarshalJSON(value []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(value, &raw); err != nil {
		return err
	}
	if _, ok := raw["requiredIntNonPointer"]; raw != nil && !ok {
		return fmt.Errorf("field requiredIntNonPointer in Pointer: required")
	}
	if _, ok := raw["requiredIntPointer"]; raw != nil && !ok {
		return fmt.Errorf("field requiredIntPointer in Pointer: required")
	}
	type Plain Pointer
	var plain Plain
	if err := json.Unmarshal(value, &plain); err != nil {
		return err
	}
	if v, ok := raw["boolWithDefault"]; !ok || v == nil {
		var defaultBoolWithDefault bool = true
		plain.BoolWithDefault = &defaultBoolWithDefault
	}
	if v, ok := raw["durationWithDefault"]; !ok || v == nil {
		defaultDuration, err := time.ParseDuration("20s")
		if err != nil {
			return fmt.Errorf("failed to parse the \"20s\" default value for field durationWithDefault: %w", err)
		}
		plain.DurationWithDefault = &defaultDuration

	}
	if v, ok := raw["intWithDefault"]; !ok || v == nil {
		var defaultIntWithDefault int = 42
		plain.IntWithDefault = &defaultIntWithDefault
	}
	if v, ok := raw["normalDefault"]; !ok || v == nil {
		plain.NormalDefault = "world"
	}
	if v, ok := raw["sliceWithDefault"]; !ok || v == nil {
		plain.SliceWithDefault = []string{
			"a",
			"b",
		}
	}
	if v, ok := raw["stringWithDefault"]; !ok || v == nil {
		var defaultStringWithDefault string = "hello"
		plain.StringWithDefault = &defaultStringWithDefault
	}
	*j = Pointer(plain)
	return nil
}

// UnmarshalYAML implements yaml.Unmarshaler.
func (j *Pointer) UnmarshalYAML(value *yaml.Node) error {
	var raw map[string]interface{}
	if err := value.Decode(&raw); err != nil {
		return err
	}
	if _, ok := raw["requiredIntNonPointer"]; raw != nil && !ok {
		return fmt.Errorf("field requiredIntNonPointer in Pointer: required")
	}
	if _, ok := raw["requiredIntPointer"]; raw != nil && !ok {
		return fmt.Errorf("field requiredIntPointer in Pointer: required")
	}
	type Plain Pointer
	var plain Plain
	if err := value.Decode(&plain); err != nil {
		return err
	}
	if v, ok := raw["boolWithDefault"]; !ok || v == nil {
		var defaultBoolWithDefault bool = true
		plain.BoolWithDefault = &defaultBoolWithDefault
	}
	if v, ok := raw["durationWithDefault"]; !ok || v == nil {
		defaultDuration, err := time.ParseDuration("20s")
		if err != nil {
			return fmt.Errorf("failed to parse the \"20s\" default value for field durationWithDefault: %w", err)
		}
		plain.DurationWithDefault = &defaultDuration

	}
	if v, ok := raw["intWithDefault"]; !ok || v == nil {
		var defaultIntWithDefault int = 42
		plain.IntWithDefault = &defaultIntWithDefault
	}
	if v, ok := raw["normalDefault"]; !ok || v == nil {
		plain.NormalDefault = "world"
	}
	if v, ok := raw["sliceWithDefault"]; !ok || v == nil {
		plain.SliceWithDefault = []string{
			"a",
			"b",
		}
	}
	if v, ok := raw["stringWithDefault"]; !ok || v == nil {
		var defaultStringWithDefault string = "hello"
		plain.StringWithDefault = &defaultStringWithDefault
	}
	*j = Pointer(plain)
	return nil
}
